Created
January 15, 2016 11:52
-
-
Save abidibo/2e755a1df276f9a11130 to your computer and use it in GitHub Desktop.
Track Subclasses in Python
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
class PluginMount(type): | |
def __init__(cls, name, bases, attrs): | |
print cls | |
if not hasattr(cls, 'plugins'): | |
cls.plugins = [] | |
else: | |
print cls.plugins | |
cls.plugins.append(cls) | |
print cls.plugins | |
class PasswordValidator(object): | |
__metaclass__ = PluginMount | |
class SucaValidator(PasswordValidator): | |
pass | |
print SucaValidator.minchia | |
PasswordValidator.minchia = 'lol' | |
print SucaValidator.minchia |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment