This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pathlib.Path: glob and rglob should accept PathLike patterns
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, ciupicri, nanjekyejoannah, serhiy.storchaka
Priority: normal Keywords:

Created on 2018-12-10 10:54 by ciupicri, last changed 2022-04-11 14:59 by admin.

Messages (8)
msg331491 - (view) Author: Cristian Ciupitu (ciupicri) * Date: 2018-12-10 10:54
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'))))
msg331503 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-12-10 12:24
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.
msg331507 - (view) Author: Cristian Ciupitu (ciupicri) * Date: 2018-12-10 13:07
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'.
msg331567 - (view) Author: Cristian Ciupitu (ciupicri) * Date: 2018-12-11 04:06
Err, I meant os.path.join instead of os.path.combine.
msg343840 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2019-05-29 00:16
Since this is not considered an issue, I will just add tests to confirm this behavior and close this.
msg356682 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-11-15 15:20
@nanjekyejoannah, are you still interested in adding tests or can i add tests?
msg356684 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2019-11-15 15:56
@BTaskaya From what I see, there is no consensus yet.If you are interested in exploring, go on.
msg356728 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-11-15 23:43
> 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?
History
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79634
2019-11-15 23:43:31BTaskayasetmessages: + msg356728
2019-11-15 15:56:23nanjekyejoannahsetmessages: + msg356684
2019-11-15 15:20:49BTaskayasetnosy: + BTaskaya
messages: + msg356682
2019-05-29 00:16:03nanjekyejoannahsetnosy: + nanjekyejoannah
messages: + msg343840
2018-12-14 20:45:38terry.reedysetstage: test needed
type: enhancement
versions: + Python 3.8, - Python 3.7
2018-12-11 04:06:34ciupicrisetmessages: + msg331567
2018-12-10 13:07:21ciupicrisetmessages: + msg331507
2018-12-10 12:24:55serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg331503
2018-12-10 10:54:42ciupicricreate