-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pathlib.Path.glob() does not list dangling symlink when pattern is the exact filename #89769
Comments
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? |
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 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. |
By the way note that path.glob('**/my_symlink') also does return the dangling symlink match. And glob.glob('my_symlink') also returns a dangling symlink. |
… for precise match (GH-29655) Co-authored-by: Barney Gale <barney.gale@gmail.com>
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:
The text was updated successfully, but these errors were encountered: