[flake8-use-pathlib] Fix PTH116 false positive when stat is passed a file descriptor (#17709)
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e17e1e860b
commit
67ef370733
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user