-
-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
pathlib: Highlight pathlib operator behavior with anchored paths #87691
Comments
In the '/' operator documentation for https://docs.python.org/3/library/pathlib.html#operators The behavior (prefer the second/right-hand root/anchor) is only explained in the https://docs.python.org/3/library/pathlib.html#pathlib.PurePath I ran into this while helping migrate a code base that was using "naive" concatenation of strings, so this:
was migrated to:
Note that, of course, we missed the leading "/". Although the docs _do_ describe the behavior somewhere else, I believe it's worth being redundant in the operator section. I believe it's a reasonable mistake to warn new users against, specially since "naive" concatenation is a common "ugly" pattern that many would be migrating from. Plus, a leading "/" is easy to miss, which would only compound the confusion if you are seeing your path "omit the (left-hand) Path object" (because the anchored string took precedence). |
The behaviour is fully explained a couple paragraphs above, but it may be useful to have a brief example to cover the behaviour.
…-100737) The behaviour is fully explained a couple paragraphs above, but it may be useful to have a brief example to cover the behaviour. Automerge-Triggered-By: GH:hauntsaninja
…cs (pythonGH-100737) The behaviour is fully explained a couple paragraphs above, but it may be useful to have a brief example to cover the behaviour. (cherry picked from commit 1ae619c) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Automerge-Triggered-By: GH:hauntsaninja
…cs (pythonGH-100737) The behaviour is fully explained a couple paragraphs above, but it may be useful to have a brief example to cover the behaviour. (cherry picked from commit 1ae619c) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Automerge-Triggered-By: GH:hauntsaninja
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.
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.join In particular, the previous use of "anchor" was incorrect given the pathlib definition of "anchor". 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>
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>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: