-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Special methods (__foo__) don't work as expected on ProxyObject methods #249
Comments
Am I reading this correctly that you create an object with a property >>> 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
The text was updated successfully, but these errors were encountered: