Skip to content

Check For @singledispatch Decorator in classes without @staticmethod #6917

Closed
@cdreimer-thewriter

Description

@cdreimer-thewriter

Current problem

The representative code implements single dispatching with the @singledispatch and @staticmethod decorators in a class.

Class Board():

   @singledispatch
   @staticmethod
   def convert_position(position):
        [...]
   
    @convert_position.register(str)
    @staticmethod
    def _(position: str) -> tuple:
        [...]

    @convert_position.register(tuple)
    @staticmethod
    def _(position: tuple) -> str:
        [...]

Pylint reports nothing unusual about using @singledispatch inside a class.

Desired solution

Pylint should check for the @singledispatch decorator inside a class. According to the documentation, the @singledispatchmethod decorator is for class methods.

Additional context

The code works with the @singledispatch decorator as long as the single dispatch methods have the @staticmethod decorator (i.e., stateless methods). If the @staticmethod decorators were removed or replaced with the @classmethod decorator, the code stops working and the resulting error messages will indirectly point out the wrong decorator. A pylint check would prevent that from happening.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement ✨Improvement to a componentGood first issueFriendly and approachable by new contributorsHacktoberfestNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions