Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
GH-103548: Improve performance ofpathlib.Path.[is_]absolute()#103549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
871dbdb GH-103548: Improve performance of `pathlib.Path.[is_]absolute()`
barneygale72c6652 Fix `absolute()` on Windows.
barneygale37153c5 Simplify code
barneygalee2558bb Merge branch 'main' into gh-103548-absolute-perf
barneygale6e984bc Merge branch 'main' into gh-103548-absolute-perf
barneygale7d1ebe2 Merge branch 'main' into gh-103548-absolute-perf
barneygalecfe99fd Improve news blurb
barneygale12957bf Suggestions from code review.
barneygaleb476ce6 Mention Path.cwd() in comment.
barneygaleb32b86c Clarify comment
barneygaleFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
GH-103548: Improve performance of
pathlib.Path.[is_]absolute()Pass the *unnormalized* path to `os.path.isabs()`.When making an empty path absolute, avoid calling `os.path.join()`, andprevent pathlib from later re-normalizing the result of `os.getcwd()` bystoring it as `path._str`.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit871dbdb455ee4b3aa6f77a22613b3719b1ccf8c9
There are no files selected for viewing
9 changes: 7 additions & 2 deletionsLib/pathlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -650,7 +650,7 @@ def is_absolute(self): | ||
| # ntpath.isabs() is defective - see GH-44626 . | ||
| if self._flavour is ntpath: | ||
| return bool(self.drive and self.root) | ||
AlexWaygood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return self._flavour.isabs(self._raw_path) | ||
| def is_reserved(self): | ||
| """Return True if the path contains one of the special names reserved | ||
| @@ -857,8 +857,13 @@ def absolute(self): | ||
| elif self.drive: | ||
| # There is a CWD on each drive-letter drive. | ||
| cwd = self._flavour.abspath(self.drive) | ||
| elif self._tail: | ||
| cwd = os.getcwd() | ||
| else: | ||
| path_str = os.getcwd() | ||
| path = type(self)(path_str) | ||
| path._str = path_str # Fully normalized string from getcwd(). | ||
| return path | ||
| return type(self)(cwd, self._raw_path) | ||
| def resolve(self, strict=False): | ||
3 changes: 3 additions & 0 deletionsMisc/NEWS.d/next/Library/2023-04-14-21-16-05.gh-issue-103548.lagdpp.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Improve performance of:meth:`pathlib.PurePath.is_absolute` and | ||
AlexWaygood marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| :meth:`pathlib.Path.absolute` by working with unnormalized paths and | ||
| avoiding unnecessary joining. | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.