Skip to content

Commit

Permalink
Fix false negative for property-with-parameters (#9592)
Browse files Browse the repository at this point in the history
In the case of parameters which are ``positional-only``, ``keyword-only``, ``variadic positional`` or
``variadic keyword``. Set the confidence level to HIGH for the ``property-with-parameters`` check 
and regenerate the functional tests.

Closes #9584
  • Loading branch information
mbyrnepr2 committed May 3, 2024
1 parent a831422 commit 3c8be8e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 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
5 changes: 2 additions & 3 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,12 +1410,11 @@ 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)
):
self.add_message("property-with-parameters", node=node)
self.add_message("property-with-parameters", node=node, confidence=HIGH)

def _check_invalid_overridden_method(
self,
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:HIGH
property-with-parameters:11:4:11:9:Cls.b:Cannot have defined parameters for properties:HIGH
property-with-parameters:15:4:15:9:Cls.c:Cannot have defined parameters for properties:HIGH
property-with-parameters:19:4:19:9:Cls.d:Cannot have defined parameters for properties:HIGH
property-with-parameters:23:4:23:9:Cls.e:Cannot have defined parameters for properties:HIGH

0 comments on commit 3c8be8e

Please sign in to comment.