Created
October 9, 2017 10:49
-
-
Save misebox/35d28ac7e41f6d20c8fd797c4611716d to your computer and use it in GitHub Desktop.
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
def has_methods(*methods): | |
def decorator(Base): | |
def __subclasshook__(Class, Subclass): | |
if Class is Base: | |
attributes = collections.ChainMap(*(Superclass.__dict__ for Superclass in Subclass.__mro__)) | |
if all(method in attributes for method in methods): | |
return True | |
return NotImplemented | |
Base.__subclasshook__ = classmethod(__subclasshook__) | |
return Base | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment