Last active
July 2, 2021 18:20
-
-
Save rafaellehmkuhl/0185fdd86a16854781e4cc958aa810e9 to your computer and use it in GitHub Desktop.
MyPy abstract method implementation check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import abc | |
from typing import List, Type | |
class AbstractClass(metaclass=abc.ABCMeta): | |
def __init__(self) -> None: | |
pass | |
@staticmethod | |
@abc.abstractmethod | |
def is_ok() -> bool: | |
pass | |
@staticmethod | |
def available_subclasses() -> List[Type["AbstractClass"]]: | |
available_interfaces = [] | |
for subclass in AbstractClass.__subclasses__(): | |
is_ok_method = getattr(subclass, "is_ok", None) | |
if callable(is_ok_method): | |
available_interfaces.append(subclass) | |
return available_interfaces | |
# return [subclass for subclass in AbstractClass.__subclasses__() if subclass.is_ok()] | |
class ConcreteClass(AbstractClass): | |
def __init__(self) -> None: | |
super().__init__() | |
# @staticmethod | |
# def is_ok() -> bool: | |
# return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment