Issue 35453: pathlib.Path: glob and rglob should accept PathLike patterns
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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) * ![]() |
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:09 | admin | set | github: 79634 |
| 2019-11-15 23:43:31 | BTaskaya | set | messages: + msg356728 |
| 2019-11-15 15:56:23 | nanjekyejoannah | set | messages: + msg356684 |
| 2019-11-15 15:20:49 | BTaskaya | set | nosy:
+ BTaskaya messages: + msg356682 |
| 2019-05-29 00:16:03 | nanjekyejoannah | set | nosy:
+ nanjekyejoannah messages: + msg343840 |
| 2018-12-14 20:45:38 | terry.reedy | set | stage: test needed type: enhancement versions: + Python 3.8, - Python 3.7 |
| 2018-12-11 04:06:34 | ciupicri | set | messages: + msg331567 |
| 2018-12-10 13:07:21 | ciupicri | set | messages: + msg331507 |
| 2018-12-10 12:24:55 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg331503 |
| 2018-12-10 10:54:42 | ciupicri | create | |
