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 Foo(object): | |
# ... | |
# is syntactic sugar for | |
# Foo = type('Foo', (object,), {...}) | |
# And with a metaclass Meta: | |
# Bar = Meta('Bar', (object,), {...}) | |
def metafunc(name, bases, dict): | |
print "I created a new class %s%s from %s" % (name, bases, dict) | |
return type(name, bases, dict) |
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 Additive(type): | |
def __add__(self, x): | |
return type("Additive", (self, x), {}) | |
class A(object): | |
__metaclass__ = Additive | |
def foo(self): | |
print "foo" | |
class B(object): |
NewerOlder