Skip to content

Instantly share code, notes, and snippets.

@misebox
Created October 9, 2017 10:49
Show Gist options
  • Save misebox/35d28ac7e41f6d20c8fd797c4611716d to your computer and use it in GitHub Desktop.
Save misebox/35d28ac7e41f6d20c8fd797c4611716d to your computer and use it in GitHub Desktop.
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