-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-87691: clarify use of anchor in pathlib docs #100782
Conversation
This is feedback from python#100737 (comment) This matches the wording from the `os.path.join` docs better: https://docs.python.org/3/library/os.path.html#os.path.join In particular, the previous use of "anchor" was incorrect given the pathlib definition of "anchor". While matching wording, I noticed that the constructor section uses the word "segment". This word does not appear elsewhere in the docs or code; we already have "part" and "component" to refer to the same concept in the pathlib context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with some small nits; feel free to merge if @barneygale is on board.
Doc/library/pathlib.rst
Outdated
|
||
>>> PurePath('/etc', '/usr', 'lib64') | ||
PurePosixPath('/usr/lib64') | ||
>>> PureWindowsPath('c:/Windows', 'd:bar') | ||
PureWindowsPath('d:bar') | ||
|
||
However, in a Windows path, changing the local root doesn't discard the | ||
previous drive setting:: | ||
On Windows, the drive letter is not reset when a drive-less absolute path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the drive necessarily one letter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I think the drive can be a UNC path. This also would need to get fixed in the os.path.join documentation: https://docs.python.org/3/library/os.path.html#os.path.join
>>> PureWindowsPath("hello", "//host/computer/dir", "/asdf")
PureWindowsPath('//host/computer/asdf')
>>> ntpath.join("hello", "//host/computer/dir", "/asdf")
'//host/computer/asdf'
I'll update to "drive" and open a second PR for os.path.join if @barneygale concurs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"drive" makes more sense to me too.
They're not quite the same! A "part" is a component in a fully-normalized path. Unless it's an anchor, a part can't contain any path separators. Contrast this with a "segment" which can contain separators and might even be a fully-fledged path in its own right! |
re segment: Ah, makes sense, I knew I had to be missing something I filed #100783 for some issues in |
Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Barney Gale <barney.gale@gmail.com>
Thanks @hauntsaninja for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
GH-100786 is a backport of this pull request to the 3.11 branch. |
GH-100787 is a backport of this pull request to the 3.10 branch. |
This is feedback from https://github.com/python/cpython/pull/100737GH-discussion_r1062968696 This matches the wording from the `os.path.join` docs better: https://docs.python.org/3/library/os.path.htmlGH-os.path.join In particular, the previous use of "anchor" was incorrect given the pathlib definition of "anchor". (cherry picked from commit 2f2fa03) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Barney Gale <barney.gale@gmail.com>
This is feedback from https://github.com/python/cpython/pull/100737GH-discussion_r1062968696 This matches the wording from the `os.path.join` docs better: https://docs.python.org/3/library/os.path.htmlGH-os.path.join In particular, the previous use of "anchor" was incorrect given the pathlib definition of "anchor". (cherry picked from commit 2f2fa03) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Barney Gale <barney.gale@gmail.com>
This is feedback from https://github.com/python/cpython/pull/100737GH-discussion_r1062968696 This matches the wording from the `os.path.join` docs better: https://docs.python.org/3/library/os.path.htmlGH-os.path.join In particular, the previous use of "anchor" was incorrect given the pathlib definition of "anchor". (cherry picked from commit 2f2fa03) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Barney Gale <barney.gale@gmail.com>
This is feedback from https://github.com/python/cpython/pull/100737GH-discussion_r1062968696 This matches the wording from the `os.path.join` docs better: https://docs.python.org/3/library/os.path.htmlGH-os.path.join In particular, the previous use of "anchor" was incorrect given the pathlib definition of "anchor". (cherry picked from commit 2f2fa03) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Barney Gale <barney.gale@gmail.com>
@barneygale, fancy adding yourself to CODEOWNERS so you get automatically requested for review on PRs touching |
You could also consider adding yourself to https://devguide.python.org/core-developers/experts/index.html#experts as a pathlib expert — there's already at least one triager on the experts list :-) |
This is feedback from #100737 (comment)
This matches the wording from the
os.path.join
docs better: https://docs.python.org/3/library/os.path.html#os.path.joinIn particular, the previous use of "anchor" was incorrect given the pathlib definition of "anchor".
Co-authored-by: barneygale