Skip to content

Commit

Permalink
Fix false negative for property-with-parameters in the case of pa…
Browse files Browse the repository at this point in the history
…rameters which are ``positional-only``, ``keyword-only``, ``variadic positional`` or ``variadic keyword``.

Closes pylint-dev#9584
  • Loading branch information
mbyrnepr2 committed May 2, 2024
1 parent a831422 commit 9bfd637
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9584.false_negative
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix false negative for ``property-with-parameters`` in the case of parameters which are ``positional-only``, ``keyword-only``, ``variadic positional`` or ``variadic keyword``.

Closes #9584
3 changes: 1 addition & 2 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,8 +1410,7 @@ def form_annotations(arguments: nodes.Arguments) -> list[str]:

def _check_property_with_parameters(self, node: nodes.FunctionDef) -> None:
if (
node.args.args
and len(node.args.args) > 1
len(node.args.arguments) > 1
and decorated_with_property(node)
and not is_property_setter(node)
):
Expand Down
20 changes: 18 additions & 2 deletions tests/functional/p/property_with_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@

class Cls:
@property
def attribute(self, param, param1): # [property-with-parameters]
return param + param1
def a(self, arg): # [property-with-parameters]
return arg

@property
def b(self, arg, /): # [property-with-parameters]
return arg

@property
def c(self, *, arg): # [property-with-parameters]
return arg

@property
def d(self, *args): # [property-with-parameters]
return args

@property
def e(self, **kwargs): # [property-with-parameters]
return kwargs


class MyClassBase(metaclass=ABCMeta):
Expand Down
6 changes: 5 additions & 1 deletion tests/functional/p/property_with_parameters.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
property-with-parameters:7:4:7:17:Cls.attribute:Cannot have defined parameters for properties:UNDEFINED
property-with-parameters:7:4:7:9:Cls.a:Cannot have defined parameters for properties:UNDEFINED
property-with-parameters:11:4:11:9:Cls.b:Cannot have defined parameters for properties:UNDEFINED
property-with-parameters:15:4:15:9:Cls.c:Cannot have defined parameters for properties:UNDEFINED
property-with-parameters:19:4:19:9:Cls.d:Cannot have defined parameters for properties:UNDEFINED
property-with-parameters:23:4:23:9:Cls.e:Cannot have defined parameters for properties:UNDEFINED

0 comments on commit 9bfd637

Please sign in to comment.