[flake8-use-pathlib] Fix PTH116 false positive when stat is passed a file descriptor (#17709)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new red-knot panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[Knot Playground] Release / publish (push) Waiting to run

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
Victor Hugo Gomes 2025-05-01 03:16:28 -03:00 committed by GitHub
parent e17e1e860b
commit 67ef370733
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -56,6 +56,7 @@ open(x)
def foo(y: int):
open(y)
# https://github.com/astral-sh/ruff/issues/17691
def f() -> int:
return 1
@ -68,3 +69,16 @@ open(byte_str)
def bytes_str_func() -> bytes:
return b"foo"
open(bytes_str_func())
# https://github.com/astral-sh/ruff/issues/17693
os.stat(1)
os.stat(x)
def func() -> int:
return 2
os.stat(func())
def bar(x: int):
os.stat(x)

View file

@ -55,7 +55,16 @@ pub(crate) fn replaceable_by_pathlib(checker: &Checker, call: &ExprCall) {
// PTH114
["os", "path", "islink"] => OsPathIslink.into(),
// PTH116
["os", "stat"] => OsStat.into(),
["os", "stat"] => {
if call
.arguments
.find_positional(0)
.is_some_and(|expr| is_file_descriptor(expr, checker.semantic()))
{
return;
}
OsStat.into()
}
// PTH117
["os", "path", "isabs"] => OsPathIsabs.into(),
// PTH118