mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Detect SIM910 when using variadic keyword arguments, i.e., **kwargs
(#13503)
Closes https://github.com/astral-sh/ruff/issues/13493
This commit is contained in:
parent
f27a8b8c7a
commit
11f06e0d55
3 changed files with 75 additions and 2 deletions
|
@ -738,9 +738,26 @@ pub fn is_list(binding: &Binding, semantic: &SemanticModel) -> bool {
|
|||
|
||||
/// Test whether the given binding can be considered a dictionary.
|
||||
///
|
||||
/// For this, we check what value might be associated with it through it's initialization and
|
||||
/// what annotation it has (we consider `dict` and `typing.Dict`).
|
||||
/// For this, we check what value might be associated with it through it's initialization,
|
||||
/// what annotation it has (we consider `dict` and `typing.Dict`), and if it is a variadic keyword
|
||||
/// argument parameter.
|
||||
pub fn is_dict(binding: &Binding, semantic: &SemanticModel) -> bool {
|
||||
// ```python
|
||||
// def foo(**kwargs):
|
||||
// ...
|
||||
// ```
|
||||
if matches!(binding.kind, BindingKind::Argument) {
|
||||
if let Some(Stmt::FunctionDef(ast::StmtFunctionDef { parameters, .. })) =
|
||||
binding.statement(semantic)
|
||||
{
|
||||
if let Some(kwarg_parameter) = parameters.kwarg.as_deref() {
|
||||
if kwarg_parameter.name.range() == binding.range() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
check_type::<DictChecker>(binding, semantic)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue