mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +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:
|
def f(x: None) -> None:
|
||||||
_ = cast(Any, _identity)(x=x)
|
_ = 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(
|
fn function(
|
||||||
argumentable: Argumentable,
|
argumentable: Argumentable,
|
||||||
parameters: &Parameters,
|
parameters: &Parameters,
|
||||||
values: &Scope,
|
scope: &Scope,
|
||||||
semantic: &SemanticModel,
|
semantic: &SemanticModel,
|
||||||
dummy_variable_rgx: &Regex,
|
dummy_variable_rgx: &Regex,
|
||||||
ignore_variadic_names: bool,
|
ignore_variadic_names: bool,
|
||||||
|
@ -241,7 +241,7 @@ fn function(
|
||||||
call(
|
call(
|
||||||
argumentable,
|
argumentable,
|
||||||
args,
|
args,
|
||||||
values,
|
scope,
|
||||||
semantic,
|
semantic,
|
||||||
dummy_variable_rgx,
|
dummy_variable_rgx,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
|
@ -252,7 +252,7 @@ fn function(
|
||||||
fn method(
|
fn method(
|
||||||
argumentable: Argumentable,
|
argumentable: Argumentable,
|
||||||
parameters: &Parameters,
|
parameters: &Parameters,
|
||||||
values: &Scope,
|
scope: &Scope,
|
||||||
semantic: &SemanticModel,
|
semantic: &SemanticModel,
|
||||||
dummy_variable_rgx: &Regex,
|
dummy_variable_rgx: &Regex,
|
||||||
ignore_variadic_names: bool,
|
ignore_variadic_names: bool,
|
||||||
|
@ -278,7 +278,7 @@ fn method(
|
||||||
call(
|
call(
|
||||||
argumentable,
|
argumentable,
|
||||||
args,
|
args,
|
||||||
values,
|
scope,
|
||||||
semantic,
|
semantic,
|
||||||
dummy_variable_rgx,
|
dummy_variable_rgx,
|
||||||
diagnostics,
|
diagnostics,
|
||||||
|
@ -288,13 +288,13 @@ fn method(
|
||||||
fn call<'a>(
|
fn call<'a>(
|
||||||
argumentable: Argumentable,
|
argumentable: Argumentable,
|
||||||
parameters: impl Iterator<Item = &'a Parameter>,
|
parameters: impl Iterator<Item = &'a Parameter>,
|
||||||
values: &Scope,
|
scope: &Scope,
|
||||||
semantic: &SemanticModel,
|
semantic: &SemanticModel,
|
||||||
dummy_variable_rgx: &Regex,
|
dummy_variable_rgx: &Regex,
|
||||||
diagnostics: &mut Vec<Diagnostic>,
|
diagnostics: &mut Vec<Diagnostic>,
|
||||||
) {
|
) {
|
||||||
diagnostics.extend(parameters.filter_map(|arg| {
|
diagnostics.extend(parameters.filter_map(|arg| {
|
||||||
let binding = values
|
let binding = scope
|
||||||
.get(arg.name.as_str())
|
.get(arg.name.as_str())
|
||||||
.map(|binding_id| semantic.binding(binding_id))?;
|
.map(|binding_id| semantic.binding(binding_id))?;
|
||||||
if binding.kind.is_argument()
|
if binding.kind.is_argument()
|
||||||
|
@ -317,6 +317,10 @@ pub(crate) fn unused_arguments(
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
diagnostics: &mut Vec<Diagnostic>,
|
diagnostics: &mut Vec<Diagnostic>,
|
||||||
) {
|
) {
|
||||||
|
if scope.uses_locals() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let Some(parent) = &checker.semantic().first_non_type_parent_scope(scope) else {
|
let Some(parent) = &checker.semantic().first_non_type_parent_scope(scope) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue