ruff/crates/ruff_linter/resources/test/fixtures/pylint/singledispatch_method.py
Aleksei Latyshev 0de23760ff
[pylint] Don't recommend decorating staticmethods with @singledispatch (PLE1519, PLE1520) (#10637)
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2024-04-02 16:47:31 +00:00

39 lines
925 B
Python

from functools import singledispatch, singledispatchmethod
@singledispatch
def convert_position(position):
pass
class Board:
@singledispatch # [singledispatch-method]
@classmethod
def convert_position(cls, position):
pass
@singledispatch # [singledispatch-method]
def move(self, position):
pass
@singledispatchmethod
def place(self, position):
pass
@singledispatch # [singledispatch-method]
@staticmethod
def do(position):
pass
# False negative (flagged by Pylint).
@convert_position.register
@classmethod
def _(cls, position: str) -> tuple:
position_a, position_b = position.split(",")
return (int(position_a), int(position_b))
# False negative (flagged by Pylint).
@convert_position.register
@classmethod
def _(cls, position: tuple) -> str:
return f"{position[0]},{position[1]}"