fork download
  1. class Metaclass(type):
  2. def __new__(cls, name, bases, dct):
  3. print 'Meta.new', name
  4. return type.__new__(cls, name, bases, dct)
  5. def __init__(cls, name, bases, dct):
  6. print 'Meta.init', name
  7. super(Metaclass, cls).__init__(name, bases, dct)
  8. @property
  9. def method1(self):
  10. print 'getter, lol'
  11. @method1.setter
  12. def method1(self, value):
  13. print 'setter, lol', value
  14.  
  15.  
  16. class X(object):
  17. __metaclass__ = Metaclass
  18. def foo(self): return 'foo'
  19.  
  20. X.method = lambda self: 'method'
  21. X.method1 = lambda self: 'method1'
  22. o = X()
  23. print o.foo()
  24. print o.method()
  25. print o.method1() # aaaand fail!
  26.  
  27.  
Runtime error #stdin #stdout 0.02s 6356KB
stdin
Standard input is empty
stdout
Meta.new X
Meta.init X
setter, lol <function <lambda> at 0x8f1972c>
foo
method