Repository navigation
pathlib.Path.glob() does not list dangling symlink when pattern is the exact filename #89769
Description
Activity
Create a symlink that points to file that doesn't exist:
ln -s /nonexisting_file my_symlinkThen 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?
- added3.8 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 25, 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.
Rasmus: thanks for the report, it does seem like a bug to me.
3 remaining items
- 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 - added3.11only security fixesonly security fixesand removed3.8 (EOL)end of lifeend of life
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 - added a commit that references this issue
on May 3, 2023 - added3.12only security fixesonly security fixesand removed3.11only security fixesonly security fixes3.10 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life
on May 3, 2023
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
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:
bugs.python.org fields: