GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pathlib glob ignores trailing slash in pattern · Issue #66472 · python/cpython

pathlib glob ignores trailing slash in pattern #66472

New issue
Copy link
New issue
Copy link
Closed
Closed
pathlib glob ignores trailing slash in pattern#66472
Copy link
Assignees
emilyemorehouse
Labels
3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

jocabt
mannequin
opened on Aug 26, 2014
Issue body actions
BPO 22276
Nosy @pitrou, @bitdancer, @emilyemorehouse, @robbuckley, @akulakov
PRs
  • bpo-22276: Fix pathlib.Path.glob not to ignore trailing path separator #10349
  • 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 = 'https://github.com/emilyemorehouse'
    closed_at = None
    created_at = <Date 2014-08-26.11:37:22.662>
    labels = ['3.8', 'type-bug', 'library']
    title = 'pathlib glob ignores trailing slash in pattern'
    updated_at = <Date 2021-11-21.02:47:05.959>
    user = 'https://bugs.python.org/jocabt'

    bugs.python.org fields:

    activity = <Date 2021-11-21.02:47:05.959>
    actor = 'andrei.avk'
    assignee = 'emilyemorehouse'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2014-08-26.11:37:22.662>
    creator = 'joca.bt'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 22276
    keywords = ['patch']
    message_count = 9.0
    messages = ['225914', '226033', '226034', '226036', '226095', '226102', '406700', '406701', '406702']
    nosy_count = 7.0
    nosy_names = ['pitrou', 'r.david.murray', 'cvrebert', 'joca.bt', 'emilyemorehouse', 'robbuckley', 'andrei.avk']
    pr_nums = ['10349']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue22276'
    versions = ['Python 3.8']

    Activity

    1. jocabt commented on Aug 26, 2014

      @jocabt
      jocabtmannequin
      on Aug 26, 2014
      MannequinAuthor
      More actions

      Both fnmatch and glob support the "*/" glob. However, pathlib does not seem to handle this kind of globs correctly.

      dir = Path("/a/directory/")
      file = Path("/a/file")
      print(dir.match("*/")) # True
      print(file.match("*/")) # True

      The "/" is being discarded by the match, resulting in incorrect matches.

      Both the fnmatch and glob libraries support this correct.
      print(fnmatch("/a/directory/", "*/")) # True
      print(fnmatch("/a/file", "*/")) # False

      bpo-21039 may be related to this.

    2. jocabt
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Aug 26, 2014
    3. pitrou commented on Aug 28, 2014

      @pitrou
      pitrou
      on Aug 28, 2014
      Member
      More actions

      What is "*/" supposed to do? Only select directories?

    4. jocabt commented on Aug 28, 2014

      @jocabt
      jocabtmannequin
      on Aug 28, 2014
      MannequinAuthor
      More actions

      Yes.

    5. bitdancer commented on Aug 28, 2014

      @bitdancer
      bitdancer
      on Aug 28, 2014
      Member
      More actions

      Heh. I never noticed that about shell globs, but it is logical. Learn something new every day.

    6. pitrou commented on Aug 29, 2014

      @pitrou
      pitrou
      on Aug 29, 2014
      Member
      More actions

      Well, it would be logical if pathlib gave special meaning to trailing slashes, which it (still) doesn't :-) I'm still not fond of encoding path characteristics in the path string itself.
      (and what about symlinks? etc.)

    7. pitrou
      changed the title [-]pathlib glob issues[/-] [+]pathlib glob ignores trailing slash in pattern[/+] on Aug 29, 2014
    8. bitdancer commented on Aug 29, 2014

      @bitdancer
      bitdancer
      on Aug 29, 2014
      Member
      More actions

      I'm not sure that a trailing '/' is a "path characteristic" in the same sense that a symlink is. Whether the path has a trailing slash or not has meaning both to the user and to the OS. pathlib isn't just modeling actual path objects on the file system, but the abstract concept of a path, and in the abstract context the presence or absence of a trailing '/' as meaning.

      But that's a wider discussion than this issue :)

    9. SilentGhost
      added
      3.7 (EOL)end of lifeend of life
      on May 5, 2018
    10. SilentGhost
      assigned
      emilyemorehouse
      on May 5, 2018
    11. SilentGhost
      added
      3.8 (EOL)end of lifeend of life
      and removed
      3.7 (EOL)end of lifeend of life
      on May 5, 2018
    12. akulakov commented on Nov 21, 2021

      @akulakov
      akulakov
      on Nov 21, 2021
      Contributor
      More actions

      I have also run into this when looking into path.glob('dangling_symlink') issue.

      I can add a few things (in the examples, *myfile* is a file, not a directory):

      This is probably more common / less obscure than '*/':

      path.glob('myfile/') => True

      This is inconsistent with how shell ls command works and with glob.glob() and looks wrong.

      Path('myfile/').exists() => True

      Path('myfile/') == Path('myfile') => True

      str(Path('myfile/')) => 'myfile'

      You can compare this to behavior of ls (tested on MacOS):

      ls myfile
      myfile

      ls myfile/
      ls: myfile/: Not a directory

      I think many users will expect behavior consistent with ls and glob.glob. I've used ls in this manner before.

    13. akulakov commented on Nov 21, 2021

      @akulakov
      akulakov
      on Nov 21, 2021
      Contributor
      More actions

      I meant to say:

      path.glob('myfile/') => [PosixPath('myfile')]

    14. akulakov commented on Nov 21, 2021

      @akulakov
      akulakov
      on Nov 21, 2021
      Contributor
      More actions

      Generally if Path is created with a trailing separator, I think it should error out for all methods that apply to files, for example .touch(), read*(), write*(), others.

      This is consistent with shell commands:

      touch xyz/ touch: xyz/: Not a directory

      echo 'blah' > xyz/
      zsh: not a directory: xyz/

    15. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    16. serhiy-storchaka
      added this to Fnmatch and glob issueson May 19, 2022
    17. brettcannon
      added
      topic-pathlib
      on Jun 21, 2022
    18. barneygale commented on Jul 22, 2022

      @barneygale
      barneygale
      on Jul 22, 2022
      Contributor
      More actions

      This was fixed in #10349. This issue could be closed.

    19. barneygale commented on Jan 8, 2023

      @barneygale
      barneygale
      on Jan 8, 2023
      Contributor
      More actions

      Fixed in #10349.

    20. barneygale
      closed this as completedon Jan 8, 2023
    21. github-project-automation
      moved this to Done in Fnmatch and glob issueson Jan 8, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @emilyemorehouse
      emilyemorehouse

    Labels

    3.8 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Fnmatch and glob issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.