Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def opener(path, flags):
def foo(y: int):
open(y)


# https://github.com/astral-sh/ruff/issues/17691
def f() -> int:
return 1
Expand All @@ -68,3 +69,10 @@ def f() -> int:
def bytes_str_func() -> bytes:
return b"foo"
open(bytes_str_func())

# https://github.com/astral-sh/ruff/issues/17694
os.rename("src", "dst", src_dir_fd=3, dst_dir_fd=4)
os.rename(b"src", b"dst", src_dir_fd=3, dst_dir_fd=4)
os.rename(b"src", b"dst", src_dir_fd=3)
os.rename(b"src", b"dst", dst_dir_fd=4)
os.rename(b"src", b"dst")
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,35 @@ pub(crate) fn replaceable_by_pathlib(checker: &Checker, call: &ExprCall) {
// PTH103
["os", "mkdir"] => OsMkdir.into(),
// PTH104
["os", "rename"] => OsRename.into(),
["os", "rename"] => {
// `src_dir_fd` and `dst_dir_fd` are not supported by pathlib, so check if they are
// are set to non-default values.
// Signature as of Python 3.13 (https://docs.python.org/3/library/os.html#os.rename)
// ```text
// 0 1 2 3
// os.rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)
// ```
if call
.arguments
.find_argument_value("src_dir_fd", 2)
.is_some_and(|expr| !expr.is_none_literal_expr())
|| call
.arguments
.find_argument_value("dst_dir_fd", 3)
.is_some_and(|expr| !expr.is_none_literal_expr())
|| call
.arguments
.find_positional(0)
.is_some_and(|expr| is_bytes_string(expr, checker.semantic()))
|| call
.arguments
.find_positional(1)
.is_some_and(|expr| is_bytes_string(expr, checker.semantic()))
{
return;
}
OsRename.into()
}
// PTH105
["os", "replace"] => OsReplace.into(),
// PTH106
Expand Down
Loading