Skip to content
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

Closed
diegoe mannequin opened this issue Mar 17, 2021 · 1 comment
Closed

pathlib: Highlight pathlib operator behavior with anchored paths #87691

diegoe mannequin opened this issue Mar 17, 2021 · 1 comment
Labels
3.9 only security fixes docs Documentation in the Doc dir topic-pathlib

Comments

@diegoe
Copy link
Mannequin

diegoe mannequin commented Mar 17, 2021

BPO 43525
Nosy @diegoe
PRs
  • bpo-43525: Highlight pathlib operator behavior with anchored paths #24900
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2021-03-17.04:04:55.025>
    labels = ['3.9', 'docs']
    title = 'pathlib: Highlight pathlib operator behavior with anchored paths'
    updated_at = <Date 2021-03-17.04:24:30.717>
    user = 'https://github.com/diegoe'

    bugs.python.org fields:

    activity = <Date 2021-03-17.04:24:30.717>
    actor = 'diegoe'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2021-03-17.04:04:55.025>
    creator = 'diegoe'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43525
    keywords = ['patch']
    message_count = 1.0
    messages = ['388904']
    nosy_count = 2.0
    nosy_names = ['docs@python', 'diegoe']
    pr_nums = ['24900']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue43525'
    versions = ['Python 3.9']

    Linked PRs

    @diegoe
    Copy link
    Mannequin Author

    diegoe mannequin commented Mar 17, 2021

    In the '/' operator documentation for pathlib, the behavior for anchored paths is not described:

    https://docs.python.org/3/library/pathlib.html#operators

    The behavior (prefer the second/right-hand root/anchor) is only explained in the PurePath class:

    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:

    PROJECT_DIR = ROOT_DIR + "/project-name"
    

    was migrated to:

    PROJECT_DIR = ROOT_DIR / "/project-name"
    

    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).

    @diegoe diegoe mannequin added the 3.9 only security fixes label Mar 17, 2021
    @diegoe diegoe mannequin assigned docspython Mar 17, 2021
    @diegoe diegoe mannequin added docs Documentation in the Doc dir 3.9 only security fixes labels Mar 17, 2021
    @diegoe diegoe mannequin assigned docspython Mar 17, 2021
    @diegoe diegoe mannequin added the docs Documentation in the Doc dir label Mar 17, 2021
    @diegoe diegoe mannequin changed the title pathlib: Highlight operator behavior with anchored paths pathlib: Highlight pathlib operator behavior with anchored paths Mar 17, 2021
    @diegoe diegoe mannequin changed the title pathlib: Highlight operator behavior with anchored paths pathlib: Highlight pathlib operator behavior with anchored paths Mar 17, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Jan 4, 2023
    The behaviour is fully explained a couple paragraphs above, but it may
    be useful to have a brief example to cover the behaviour.
    miss-islington pushed a commit that referenced this issue Jan 5, 2023
    …-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
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 5, 2023
    …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
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 5, 2023
    …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
    miss-islington added a commit that referenced this issue Jan 5, 2023
    …-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
    miss-islington added a commit that referenced this issue Jan 5, 2023
    …-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
    hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Jan 5, 2023
    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.
    hauntsaninja added a commit that referenced this issue Jan 6, 2023
    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>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 6, 2023
    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>
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 6, 2023
    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>
    miss-islington added a commit that referenced this issue Jan 6, 2023
    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>
    miss-islington added a commit that referenced this issue Jan 6, 2023
    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>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes docs Documentation in the Doc dir topic-pathlib
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants