-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
fixesRelated to suggested fixes for violationsRelated to suggested fixes for violationspreviewRelated to preview mode featuresRelated to preview mode features
Description
Summary
The fix for os-path-abspath (PTH100) converts os.path.abspath to pathlib.Path.resolve, which does not do the same thing. Sometimes, as in upstream flake8-use-pathlib issue #8, pathlib.Path.absolute is the preferred replacement, but there is no exact equivalent; see python/cpython#69200. The documentation for PTH100 should explain this and the fix should be marked unsafe.
| Function | Removes ..? |
Resolves symlinks? |
|---|---|---|
abspath |
✅ | ❌ |
resolve |
✅ | ✅ |
absolute |
❌ | ❌ |
$ cat >pth100.py <<'# EOF'
import os
open("pth100_src", "w").close()
os.symlink("pth100_src", "pth100_dst")
os.mkdir("pth100_dir")
print(str(os.path.abspath("pth100_dir/../dst")).removeprefix(f"{os.getcwd()}/"))
# EOF
$ rm -fr pth100_{dir,dst,src}
$ python pth100.py
dst
$ ruff --isolated check pth100.py --select PTH100 --preview --fix
Found 1 error (1 fixed, 0 remaining).
$ cat pth100.py
import os
import pathlib
open("pth100_src", "w").close()
os.symlink("pth100_src", "pth100_dst")
os.mkdir("pth100_dir")
print(str(pathlib.Path("pth100_dir/../dst").resolve()).removeprefix(f"{os.getcwd()}/"))
$ rm -fr pth100_{dir,dst,src}
$ python pth100.py
srcVersion
ruff 0.12.10 (c68ff8d 2025-08-21)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
fixesRelated to suggested fixes for violationsRelated to suggested fixes for violationspreviewRelated to preview mode featuresRelated to preview mode features