Skip to content

pathlib.Path: glob and rglob should accept PathLike patterns #79634

Closed

Description

@ciupicri
mannequin
BPO 35453
Nosy @serhiy-storchaka, @nanjekyejoannah, @isidentical, @ciupicri

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 2018-12-10.10:54:42.124>
labels = ['3.8', 'type-feature', 'library']
title = 'pathlib.Path: glob and rglob should accept PathLike patterns'
updated_at = <Date 2019-11-15.23:43:31.989>
user = 'https://github.com/ciupicri'

bugs.python.org fields:

activity = <Date 2019-11-15.23:43:31.989>
actor = 'BTaskaya'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2018-12-10.10:54:42.124>
creator = 'ciupicri'
dependencies = []
files = []
hgrepos = []
issue_num = 35453
keywords = []
message_count = 8.0
messages = ['331491', '331503', '331507', '331567', '343840', '356682', '356684', '356728']
nosy_count = 4.0
nosy_names = ['serhiy.storchaka', 'nanjekyejoannah', 'BTaskaya', 'ciupicri']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'test needed'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue35453'
versions = ['Python 3.8']

Linked PRs

Activity

  1. ciupicri commented on Dec 10, 2018

    ciupicrimannequin
    MannequinAuthor

    pathlib.Path.glob and pathlib.Path.rglob don't work with os.PathLike patterns.

    Short example:

    from pathlib import Path, PurePath
    # fails
    tuple(Path('/etc').glob(PurePath('passwd')))    # TypeError
    tuple(Path('/etc').rglob(PurePath('passwd')))   # TypeError
    tuple(Path('C:\\').glob(PurePath('Windows')))   # AttributeError
    tuple(Path('C:\\').rglob(PurePath('Windows')))  # AttributeError
    # works
    from os import fspath
    tuple(Path('/etc').glob(fspath(PurePath('passwd'))))
    tuple(Path('/etc').rglob(fspath(PurePath('passwd'))))
    tuple(Path('C:\\').glob(fspath(PurePath('Windows'))))
    tuple(Path('C:\\').rglob(fspath(PurePath('Windows'))))
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Dec 10, 2018
  3. serhiy-storchaka commented on Dec 10, 2018

    @serhiy-storchaka
    Member

    This is for purpose. Path is not a glob pattern, and glob pattern is not a path. '*.txt' is aт ordinary file name on Linux and is invalid file name on Windows. If we wanted to accept Path in any place that accepts a string, we would make Path a subclass of str.

  4. ciupicri commented on Dec 10, 2018

    ciupicrimannequin
    MannequinAuthor

    What if the pattern has some directories in it, e.g. "SourceArt/**/*.png", how do you compose it? The traditional way is to either hardcode the separator (e.g. / or \) or use os.path.combine. I don't see why PurePath can't be used for this, e.g. PurePath('SourceArt')/"**'/'*.png'.

  5. ciupicri commented on Dec 11, 2018

    ciupicrimannequin
    MannequinAuthor

    Err, I meant os.path.join instead of os.path.combine.

  6. added
    type-featureA feature request or enhancement
    and removed on Dec 14, 2018
  7. nanjekyejoannah commented on May 29, 2019

    @nanjekyejoannah
    Contributor

    Since this is not considered an issue, I will just add tests to confirm this behavior and close this.

  8. isidentical commented on Nov 15, 2019

    @isidentical
    SponsorMember

    @nanjekyejoannah, are you still interested in adding tests or can i add tests?

  9. nanjekyejoannah commented on Nov 15, 2019

    @nanjekyejoannah
    Contributor

    @BTaskaya From what I see, there is no consensus yet.If you are interested in exploring, go on.

  10. isidentical commented on Nov 15, 2019

    @isidentical
    SponsorMember

    From what I see, there is no consensus yet.

    @serhiy.storchaka said this isn't an issue. I can add tests about this behavior (as you mentioned) or this issue can be directly resolved as not a bug. What are you thinking @nanjekyejoannah and @serhiy.storchaka?

  11. transferred this issue fromon Apr 10, 2022
  12. 4 remaining items

  13. added 3 commits that reference this issue on Jan 13, 2024
  14. barneygale commented on Jan 20, 2024

    @barneygale
    Contributor

    Resolved in 3.13 / 6313cdd / #114017

  15. added a commit that references this issue on Jan 22, 2024
  16. added 2 commits that reference this issue on Jan 26, 2024
  17. added 2 commits that reference this issue on Feb 11, 2024
  18. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions