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
E1520 recommends an invalid combination of @singledispatch
and @staticmethod
#9531
Labels
False Positive 🦟
A message is emitted but nothing 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
added
the
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
label
Apr 2, 2024
DanielNoord
added
False Positive 🦟
A message is emitted but nothing is wrong with the code
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
Help wanted 🙏
Outside help would be appreciated, good for new contributors
and removed
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
labels
Apr 19, 2024
mbyrnepr2
added a commit
to mbyrnepr2/pylint
that referenced
this issue
May 5, 2024
…thod is decorated with both ``functools.singledispatchmethod`` and ``staticmethod``. Closes pylint-dev#9531
mbyrnepr2
added a commit
that referenced
this issue
May 7, 2024
* Fix a false positive with ``singledispatchmethod-function`` when a method is decorated with both ``functools.singledispatchmethod`` and ``staticmethod``. Closes #9531
Pierre-Sassoulas
pushed a commit
that referenced
this issue
May 7, 2024
…9605) * Fix a false positive with ``singledispatchmethod-function`` when a method is decorated with both ``functools.singledispatchmethod`` and ``staticmethod``. Closes #9531 (cherry picked from commit 6df4e1d) Co-authored-by: Mark Byrne <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
False Positive 🦟
A message is emitted but nothing 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
Bug description
Hi from Ruff!
We recently received a bug report at Ruff stating that our reimplementation of E1520 was recommending an invalid combination of
@functools.singledispatch
and@staticmethod
. For example, this code runs fine, but ruff's PLE1520 rule was telling the issue reporter that they should use@singledispatch
here instead of@singledispatchmethod
. If you do so, the code raises an exception at runtime, as@staticmethod
is a descriptor, and@singledispatch
isn't designed to be stacked on top of descriptor instances (that's what@singledispatchmethod
is for). The Python docs also state that@singledispatchmethod
should be used for static methods: https://docs.python.org/3/library/functools.html#functools.singledispatchmethod.After investigating the bug, we decided to change our PLE1520 rule so that it no longer complained about
@singledispatchmethod
on top of@staticmethod
. It looks like pylint has the same incorrect behaviour here in the original PLE1520 rule, though, so I thought I'd open an issue to give you a heads-up as well!In case it's helpful, here's the fix that was contributed to Ruff to fix the bug: astral-sh/ruff#10637. The fix also involved some small changes to PLE1519 (E1519 at pylint) as well as PLE1520 (E1520 at pylint).
Command used
Pylint output
Expected behavior
Pylint version
OS / Environment
MacOS; Python 3.12.2
Additional dependencies
None
The text was updated successfully, but these errors were encountered: