Python 3 Strange Metaclass Behaviour -
i playing metaclasses in python 3: class m(type): def __new__(cls, clsname, bases, attrs): name, attr in attrs.items(): if callable(attr): attrs[name] = attr return type.__new__(cls, clsname, bases, attrs) class c(metaclass=m): def f(self, x): print(x) if __name__ == '__main__': c = c() c.f(1) c.f(2) nothing special far, hook creation of class, , substitute method with... well, itself, no wonder works. with: class m(type): def __new__(cls, clsname, bases, attrs): name, func in attrs.items(): if callable(func): attrs[name] = lambda *args, **kwds: func(*args, **kwds) return type.__new__(cls, clsname, bases, attrs) it sometime works, , doesn't: user$ python test.py 1 2 user$ python test.py traceback (most recent call last): file "./meta.py", line 23, in <module> main() file "./meta.py", line 19, in main in...