Skip to content

PTH116 should be suppressed when dir_fd is set #17776

@dscorbett

Description

@dscorbett

Summary

os-stat (PTH116) should be suppressed when dir_fd is set to a non-None value because the suggested Path methods don’t support file descriptors. This is a follow-up to #17693.

$ cat >pth116.py <<'# EOF'
import os
os.stat("x", dir_fd=3)
# EOF

$ ruff --isolated check --select PTH116 pth116.py
pth116.py:2:1: PTH116 `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`
  |
1 | import os
2 | os.stat("x", dir_fd=3)
  | ^^^^^^^ PTH116
  |

Found 1 error.

Version

ruff 0.11.8 (75effb8 2025-05-01)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions