Skip to content

Rule request: abstractmethod appears on normal class #12861

@Skylion007

Description

@Skylion007

the case where an abstractmethod decorator is used on a class that does not subclass abc.ABC uses the ABC metaclass, is probably a bug. It would be great to have a rule to detect the obvious case where it is used on the wrong type of class (when all ancestors of the class in the same file for instance).

If there is a rule that already implements this, let me know. :)

Here is a real example from PyTorch:

class RemoteCacheBackend:
    """
    A backend implementation for accessing a remote/distributed cache.
    """

    def __init__(self, cache_id: str) -> None:
        pass

    @abstractmethod
    def get(self, key: str) -> Optional[object]:
        pass

    @abstractmethod
    def put(self, key: str, data: bytes) -> None:
        pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions