Open aeriksson opened 2 years ago
Am I reading this correctly that you create an object with a property __len__
? In that case, this is expected and according to Python semantics. Consider this:
>>> class X():
... pass
...
>>> x = X()
>>> x.__len__ = lambda self: 12
>>> x.__len__(x)
12
>>> len(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'X' has no len()
Magic methods in Python are always only looked up on the type, never on the object itself.
Considering Python's duck-typing semantics, it'd be really useful if it were possible to define custom 'special functions' (like
__add__
,__str__
, etc) on ProxyObject, in order to build custom objects that mesh nicely with the rest of Python.Defining these methods is currently possible, but Python doesn't pick them up properly. For instance, consider the following code (pardon the Clojure ;)):
The expected output here should be
but in reality, what we get is: