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
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: