mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Avoid unused argument rules when functions call locals()
(#6578)
Closes https://github.com/astral-sh/ruff/issues/6576.
This commit is contained in:
parent
7f7df852e8
commit
17e7eae2f9
2 changed files with 21 additions and 6 deletions
|
@ -202,3 +202,14 @@ class C:
|
|||
###
|
||||
def f(x: None) -> None:
|
||||
_ = cast(Any, _identity)(x=x)
|
||||
|
||||
###
|
||||
# Unused arguments with `locals`.
|
||||
###
|
||||
def f(bar: str):
|
||||
print(locals())
|
||||
|
||||
|
||||
class C:
|
||||
def __init__(self, x) -> None:
|
||||
print(locals())
|
||||
|
|
|
@ -216,7 +216,7 @@ impl Argumentable {
|
|||
fn function(
|
||||
argumentable: Argumentable,
|
||||
parameters: &Parameters,
|
||||
values: &Scope,
|
||||
scope: &Scope,
|
||||
semantic: &SemanticModel,
|
||||
dummy_variable_rgx: &Regex,
|
||||
ignore_variadic_names: bool,
|
||||
|
@ -241,7 +241,7 @@ fn function(
|
|||
call(
|
||||
argumentable,
|
||||
args,
|
||||
values,
|
||||
scope,
|
||||
semantic,
|
||||
dummy_variable_rgx,
|
||||
diagnostics,
|
||||
|
@ -252,7 +252,7 @@ fn function(
|
|||
fn method(
|
||||
argumentable: Argumentable,
|
||||
parameters: &Parameters,
|
||||
values: &Scope,
|
||||
scope: &Scope,
|
||||
semantic: &SemanticModel,
|
||||
dummy_variable_rgx: &Regex,
|
||||
ignore_variadic_names: bool,
|
||||
|
@ -278,7 +278,7 @@ fn method(
|
|||
call(
|
||||
argumentable,
|
||||
args,
|
||||
values,
|
||||
scope,
|
||||
semantic,
|
||||
dummy_variable_rgx,
|
||||
diagnostics,
|
||||
|
@ -288,13 +288,13 @@ fn method(
|
|||
fn call<'a>(
|
||||
argumentable: Argumentable,
|
||||
parameters: impl Iterator<Item = &'a Parameter>,
|
||||
values: &Scope,
|
||||
scope: &Scope,
|
||||
semantic: &SemanticModel,
|
||||
dummy_variable_rgx: &Regex,
|
||||
diagnostics: &mut Vec<Diagnostic>,
|
||||
) {
|
||||
diagnostics.extend(parameters.filter_map(|arg| {
|
||||
let binding = values
|
||||
let binding = scope
|
||||
.get(arg.name.as_str())
|
||||
.map(|binding_id| semantic.binding(binding_id))?;
|
||||
if binding.kind.is_argument()
|
||||
|
@ -317,6 +317,10 @@ pub(crate) fn unused_arguments(
|
|||
scope: &Scope,
|
||||
diagnostics: &mut Vec<Diagnostic>,
|
||||
) {
|
||||
if scope.uses_locals() {
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(parent) = &checker.semantic().first_non_type_parent_scope(scope) else {
|
||||
return;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue