mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
[pylint
] Fix PLW1514
not recognizing the encoding
positional argument of codecs.open
(#18109)
<!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? --> ## Summary Fixes #18107 <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan Snapshot tests <!-- How was it tested? -->
This commit is contained in:
parent
2ceba6ae67
commit
f53c580c53
2 changed files with 14 additions and 1 deletions
|
@ -94,3 +94,6 @@ Path("foo.txt").write_text(text, **kwargs)
|
||||||
# Violation but not detectable
|
# Violation but not detectable
|
||||||
x = Path("foo.txt")
|
x = Path("foo.txt")
|
||||||
x.open()
|
x.open()
|
||||||
|
|
||||||
|
# https://github.com/astral-sh/ruff/issues/18107
|
||||||
|
codecs.open("plw1514.py", "r", "utf-8").close() # this is fine
|
||||||
|
|
|
@ -215,8 +215,18 @@ fn is_violation(call: &ast::ExprCall, qualified_name: &Callee) -> bool {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let encoding_param_pos = match qualified_name.segments() {
|
||||||
|
// The `encoding` parameter position for `codecs.open`
|
||||||
|
["codecs", _] => 2,
|
||||||
|
// The `encoding` parameter position for `_io.open` and the builtin `open`
|
||||||
|
_ => 3,
|
||||||
|
};
|
||||||
|
|
||||||
// else mode not specified, defaults to text mode
|
// else mode not specified, defaults to text mode
|
||||||
call.arguments.find_argument_value("encoding", 3).is_none()
|
call.arguments
|
||||||
|
.find_argument_value("encoding", encoding_param_pos)
|
||||||
|
.is_none()
|
||||||
}
|
}
|
||||||
["tempfile", tempfile_class @ ("TemporaryFile" | "NamedTemporaryFile" | "SpooledTemporaryFile")] =>
|
["tempfile", tempfile_class @ ("TemporaryFile" | "NamedTemporaryFile" | "SpooledTemporaryFile")] =>
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue