You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pathlib.Path: glob and rglob should accept PathLike patterns #79634
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.
ciupicri commented on Dec 10, 2018
ciupicrimannequin
MannequinAuthor
More actions
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'.
ciupicri commented on Dec 11, 2018
ciupicrimannequin
MannequinAuthor
More actions
Err, I meant os.path.join instead of os.path.combine.
@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?
Activity
ciupicri commentedon Dec 10, 2018
pathlib.Path.glob and pathlib.Path.rglob don't work with os.PathLike patterns.
Short example:
serhiy-storchaka commentedon Dec 10, 2018
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.
ciupicri commentedon Dec 10, 2018
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'.
ciupicri commentedon Dec 11, 2018
Err, I meant os.path.join instead of os.path.combine.
nanjekyejoannah commentedon May 29, 2019
Since this is not considered an issue, I will just add tests to confirm this behavior and close this.
isidentical commentedon Nov 15, 2019
@nanjekyejoannah, are you still interested in adding tests or can i add tests?
nanjekyejoannah commentedon Nov 15, 2019
@BTaskaya From what I see, there is no consensus yet.If you are interested in exploring, go on.
isidentical commentedon Nov 15, 2019
@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?
4 remaining items
pythonGH-79634 - Accept path-like objects as pathlib glob patterns.
pythonGH-79634: Accept path-like objects as pathlib glob patterns.
GH-79634: Accept path-like objects as pathlib glob patterns. (#114017)
barneygale commentedon Jan 20, 2024
Resolved in 3.13 / 6313cdd / #114017
pythonGH-79634: Accept path-like objects as pathlib glob patterns. (p…
pythonGH-79634: Speed up globbing by removing `joinpath()` call.
GH-79634: Speed up pathlib globbing by removing `joinpath()` call. (#…
pythonGH-79634: Accept path-like objects as pathlib glob patterns. (p…
pythonGH-79634: Speed up pathlib globbing by removing `joinpath()` ca…
pythonGH-79634: Accept path-like objects as pathlib glob patterns. (p…