mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[pylint
] Also emit PLR0206
for properties with variadic parameters (#11200)
This commit is contained in:
parent
7e28c80354
commit
21d824abfd
3 changed files with 29 additions and 11 deletions
|
@ -28,3 +28,13 @@ class MyClassBase(metaclass=ABCMeta):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def example(self, value):
|
def example(self, value):
|
||||||
"""Setter."""
|
"""Setter."""
|
||||||
|
|
||||||
|
|
||||||
|
class VariadicParameters:
|
||||||
|
@property
|
||||||
|
def attribute_var_args(self, *args): # [property-with-parameters]
|
||||||
|
return sum(args)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def attribute_var_kwargs(self, **kwargs): #[property-with-parameters]
|
||||||
|
return {key: value * 2 for key, value in kwargs.items()}
|
||||||
|
|
|
@ -51,20 +51,13 @@ pub(crate) fn property_with_parameters(
|
||||||
decorator_list: &[Decorator],
|
decorator_list: &[Decorator],
|
||||||
parameters: &Parameters,
|
parameters: &Parameters,
|
||||||
) {
|
) {
|
||||||
let semantic = checker.semantic();
|
if parameters.len() <= 1 {
|
||||||
if !decorator_list
|
|
||||||
.iter()
|
|
||||||
.any(|decorator| semantic.match_builtin_expr(&decorator.expression, "property"))
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if parameters
|
let semantic = checker.semantic();
|
||||||
.posonlyargs
|
if decorator_list
|
||||||
.iter()
|
.iter()
|
||||||
.chain(¶meters.args)
|
.any(|decorator| semantic.match_builtin_expr(&decorator.expression, "property"))
|
||||||
.chain(¶meters.kwonlyargs)
|
|
||||||
.count()
|
|
||||||
> 1
|
|
||||||
{
|
{
|
||||||
checker
|
checker
|
||||||
.diagnostics
|
.diagnostics
|
||||||
|
|
|
@ -26,4 +26,19 @@ property_with_parameters.py:15:9: PLR0206 Cannot have defined parameters for pro
|
||||||
16 | return param + param1
|
16 | return param + param1
|
||||||
|
|
|
|
||||||
|
|
||||||
|
property_with_parameters.py:35:9: PLR0206 Cannot have defined parameters for properties
|
||||||
|
|
|
||||||
|
33 | class VariadicParameters:
|
||||||
|
34 | @property
|
||||||
|
35 | def attribute_var_args(self, *args): # [property-with-parameters]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^ PLR0206
|
||||||
|
36 | return sum(args)
|
||||||
|
|
|
||||||
|
|
||||||
|
property_with_parameters.py:39:9: PLR0206 Cannot have defined parameters for properties
|
||||||
|
|
|
||||||
|
38 | @property
|
||||||
|
39 | def attribute_var_kwargs(self, **kwargs): #[property-with-parameters]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^ PLR0206
|
||||||
|
40 | return {key: value * 2 for key, value in kwargs.items()}
|
||||||
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue