Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pylint] Also emit PLR0206 for properties with variadic parameters #11200

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ def example(self):
@abstractmethod
def example(self, value):
"""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()}
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,13 @@ pub(crate) fn property_with_parameters(
decorator_list: &[Decorator],
parameters: &Parameters,
) {
let semantic = checker.semantic();
if !decorator_list
.iter()
.any(|decorator| semantic.match_builtin_expr(&decorator.expression, "property"))
{
if parameters.len() <= 1 {
return;
}
if parameters
.posonlyargs
let semantic = checker.semantic();
if decorator_list
.iter()
.chain(&parameters.args)
.chain(&parameters.kwonlyargs)
.count()
> 1
.any(|decorator| semantic.match_builtin_expr(&decorator.expression, "property"))
{
checker
.diagnostics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,19 @@ property_with_parameters.py:15:9: PLR0206 Cannot have defined parameters for pro
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