`property-with-parameters` only cares about non-`self` parameters if they're positional-or-keyword parameters
AlexWaygood opened this issue · 0 comments
Bug description
Pylint's property-with-parameters
rule checks for @property
-decorated functions that have non-self
parameters, on the grounds that additional parameters in a property function can never be used. However, the check currently only seems to care about additional parameters if they are positional-or-keyword parameters. The check does not emit any violations for additional positional-only parameters, additional keyword-only parameters, additional variadic positional parameters, or additional variadic keyword parameters. This seems off to me: defining those additional parameters is just as strange/incorrect as defining additional positional-or-keyword parameters.
To illustrate, only the a
property in the following example triggers an R0206
violation, whereas I would expect R0206
to be emitted on a
, b
, c
, d
and e
:
class Foo:
@property
def a(self, arg):
return arg
@property
def b(self, arg, /):
return arg
@property
def c(self, *, arg):
return arg
@property
def d(self, *args):
return args
@property
def e(self, **kwargs):
return kwargs
This means that R0206
is not actually emitted on the motivating example originally given for this check in #3006 (comment), since that example has an additional variadic keyword parameter (**kwargs
).
Command used
pylint foo.py --disable=W0311,C0114,C0104,C0115,C0116,R0903
Pylint output
************* Module foo
foo.py:3:3: R0206: Cannot have defined parameters for properties (property-with-parameters)
Expected output
************* Module foo
foo.py:3:3: R0206: Cannot have defined parameters for properties (property-with-parameters)
foo.py:7:3: R0206: Cannot have defined parameters for properties (property-with-parameters)
foo.py:11:3: R0206: Cannot have defined parameters for properties (property-with-parameters)
foo.py:15:3: R0206: Cannot have defined parameters for properties (property-with-parameters)
foo.py:19:3: R0206: Cannot have defined parameters for properties (property-with-parameters)
Pylint version
pylint 3.1.0
astroid 3.1.0
Python 3.12.2 (main, Feb 15 2024, 19:30:27) [Clang 15.0.0 (clang-1500.1.0.2.5)]
OS / Environment
MacOS
Additional dependencies
None