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() does not list dangling symlink when pattern is the exact filename #89769
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/akulakov'closed_at=Nonecreated_at=<Date2021-10-25.19:20:55.106>labels= ['type-bug', 'library', '3.9', '3.10', '3.11']
title='pathlib.Path.glob() does not list dangling symlink when pattern is the exact filename'updated_at=<Date2022-01-23.06:57:12.913>user='https://github.com/raek'
The issue is that _PreciseSelector follows the symlink when it checks if a path exists before yielding it as a result.
I've put up a PR with a fix; I've also added a follow_symlinks arg to exists() method because it seems more logical to be able to test if a path exists via the same method rather than having to also remember and to check for it being a symlink.
I will add docs and news a bit later today or tomorrow.
changed the title [-]pathlib.Path.glob() does not list dangling symlink when pattern is the exact filenane[/-][+]pathlib.Path.glob() does not list dangling symlink when pattern is the exact filename[/+]on Jan 23, 2022
changed the title [-]pathlib.Path.glob() does not list dangling symlink when pattern is the exact filenane[/-][+]pathlib.Path.glob() does not list dangling symlink when pattern is the exact filename[/+]on Jan 23, 2022
Activity
raek commentedon Oct 25, 2021
Create a symlink that points to file that doesn't exist:
Then try to glob for that symlink from Python using pathlib:
python3 >>> import pathlib >>> list(pathlib.Path(".").glob("my_symlink")) [] >>> list(pathlib.Path(".").glob("my_symlink*")) [PosixPath('my_symlink')]I'm a bit surprised that these two globs do not return the same results. Personally I would expect both to find the symlink.
Is this behaviour a bug or is it intentional?
akulakov commentedon Nov 20, 2021
The issue is that _PreciseSelector follows the symlink when it checks if a path exists before yielding it as a result.
I've put up a PR with a fix; I've also added a follow_symlinks arg to
exists()method because it seems more logical to be able to test if a path exists via the same method rather than having to also remember and to check for it being a symlink.I will add docs and news a bit later today or tomorrow.
akulakov commentedon Nov 20, 2021
Rasmus: thanks for the report, it does seem like a bug to me.
3 remaining items
[-]pathlib.Path.glob() does not list dangling symlink when pattern is the exact filenane[/-][+]pathlib.Path.glob() does not list dangling symlink when pattern is the exact filename[/+][-]pathlib.Path.glob() does not list dangling symlink when pattern is the exact filenane[/-][+]pathlib.Path.glob() does not list dangling symlink when pattern is the exact filename[/+]GH-89769: `pathlib.Path.glob()`: do not follow symlinks when checking…
barneygale commentedon May 3, 2023
Fixed in 3.12: #29655 / af886ff