FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-29688: document and test `pathlib.Path.absolute()`. by barneygale · Pull Request #26153 · python/cpython · GitHub

/ cpython Public

bpo-29688: document and test pathlib.Path.absolute(). - #26153

Merged
brettcannon merged 9 commits into
python:mainfrom
barneygale:bpo-29688-pathlib-absolute-docs-tests
Jan 28, 2022
Merged

bpo-29688: document and test pathlib.Path.absolute().#26153
brettcannon merged 9 commits into
python:mainfrom
barneygale:bpo-29688-pathlib-absolute-docs-tests

Conversation

barneygale commented May 15, 2021
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

This method is important and cannot be replaced with resolve()! resolve() will hit OS APIs to resolve symlinks/etc, and will fail on symlink loops, whereas absolute() just prepends the working directory and can never raise an OSError.

Also improved the table showing correspondence with os.path methods. The gory details:

  • Path.resolve() is os.path.realpath() in strict mode, with a tweaked exception type for symlink loops (backwards compat)
  • Path.absolute() is os.path.abspath() but without normalizing the path. The pathlib behaviour is better, as abspath()'s normlisation changes the meaning of the path in the presence of symlinks!

Happy to expand the tests if anyone has any ideas what else to cover.

https://bugs.python.org/issue29688

Copy link
Copy Markdown

Documentation is clear and the suggested changes looks sane to me. Will take another look after windows test failures are addressed.

Copy link
Copy Markdown
Contributor Author

Tested are fixed, thanks for taking a look.

kalvdans left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Some small remarks.

Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Lib/test/test_pathlib.py Outdated

barneygale commented May 16, 2021
edited
Loading

Copy link
Copy Markdown
Contributor Author

Note that this can't be automatically backported, as the tests' patching of getcwd() is different in 3.9 and below.

Comment thread Doc/library/pathlib.rst Outdated

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Jul 15, 2021
Comment thread Doc/library/pathlib.rst Outdated

brettcannon left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

One clarifying doc change as suggested by @domdfcoding. A news entry is also missing.

Comment thread Doc/library/pathlib.rst Outdated

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jul 17, 2021
Comment thread Doc/library/pathlib.rst Outdated

Copy link
Copy Markdown
Contributor Author

Sorry for the long delay. Does this need a NEWS entry? It adds docs and tests but doesn't change the implementation of Path.absolute()

barneygale force-pushed the bpo-29688-pathlib-absolute-docs-tests branch from 644703a to 64204fd Compare January 1, 2022 01:21
barneygale requested a review from brettcannon January 1, 2022 03:06

Copy link
Copy Markdown
Member

Sorry for the long delay. Does this need a NEWS entry? It adds docs and tests but doesn't change the implementation of Path.absolute()

It looks like you added a news entry anyway. 😄

brettcannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Question about the docs and some very minor formatting things.

Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Lib/test/test_pathlib.py Outdated
Comment thread Doc/library/pathlib.rst Outdated
Comment thread Lib/test/test_pathlib.py
Comment on lines +2662 to +2670
self.assertEqual(str(P('c:\\').absolute()), 'c:\\')
self.assertEqual(str(P('c:\\a').absolute()), 'c:\\a')
self.assertEqual(str(P('c:\\a\\b').absolute()), 'c:\\a\\b')

# UNC absolute paths.
share = '\\\\server\\share\\'
self.assertEqual(str(P(share).absolute()), share)
self.assertEqual(str(P(share + 'a').absolute()), share + 'a')
self.assertEqual(str(P(share + 'a\\b').absolute()), share + 'a\\b')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
self.assertEqual(str(P('c:\\').absolute()), 'c:\\')
self.assertEqual(str(P('c:\\a').absolute()), 'c:\\a')
self.assertEqual(str(P('c:\\a\\b').absolute()), 'c:\\a\\b')
# UNC absolute paths.
share = '\\\\server\\share\\'
self.assertEqual(str(P(share).absolute()), share)
self.assertEqual(str(P(share + 'a').absolute()), share + 'a')
self.assertEqual(str(P(share + 'a\\b').absolute()), share + 'a\\b')
self.assertEqual(str(P(r'c:\').absolute()), r'c:\')
self.assertEqual(str(P(r'c:\a').absolute()), r'c:\a')
self.assertEqual(str(P(r'c:\a\b').absolute()), r'c:\a\b')
# UNC absolute paths.
share = '\\\\server\\share\\'
self.assertEqual(str(P(share).absolute()), share)
self.assertEqual(str(P(share + 'a').absolute()), share + 'a')
self.assertEqual(str(P(share + r'a\b').absolute()), share + r'a\b')

Copy link
Copy Markdown
Member

Thanks, @barneygale !

Copy link
Copy Markdown
Contributor Author

Thanks very much for the review!

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL