Skip to content

Suppress PTH* family of rules if dir_fd= is passed #18944

@septatrix

Description

@septatrix

Summary

dir_fd can be used to operate on a file relative to a pinned directory descriptor. This is useful to prevent bugs, most importantly race conditions. The respective functionality is not available in pathlib and the suggestion to use the respective Path methods therefore does not make sense

$ ruff check --select=PTH test.py
test.py:1:1: PTH123 `open()` should be replaced by `Path.open()`
  |
1 | open("test.txt", dir_fd=1)
  | ^^^^ PTH123
  |

Found 1 error.

Version

ruff 0.11.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions