Skip to content
New issue

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

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

Already on GitHub? # to your account

property-with-parameters only cares about non-self parameters if they're positional-or-keyword parameters #9584

Closed
AlexWaygood opened this issue Apr 30, 2024 · 0 comments · Fixed by #9592 or #9619
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@AlexWaygood
Copy link
Contributor

AlexWaygood commented Apr 30, 2024

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

@AlexWaygood AlexWaygood added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 30, 2024
@DanielNoord DanielNoord added Help wanted 🙏 Outside help would be appreciated, good for new contributors False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 30, 2024
mbyrnepr2 added a commit to mbyrnepr2/pylint that referenced this issue May 2, 2024
…rameters which are ``positional-only``, ``keyword-only``, ``variadic positional`` or ``variadic keyword``.

Closes pylint-dev#9584
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.2.0 milestone May 3, 2024
Pierre-Sassoulas pushed a commit that referenced this issue May 3, 2024
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
3 participants