-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conflation of NotImplemented and NotImplementedError #419
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
Comments
I have a fix for this, just waiting for #410 to be merged which adds the |
Some methods (mainly arithmetic ones?) also raise Eg. in CPython: >>> (12).__mul__('s')
NotImplemented RustPython: >>>>> (12).__mul__('s')
Traceback (most recent call last):
File <stdin>, line 0, in <module>
TypeError: Cannot multiply 'int' object and 'str' object or CPython: >>> (12).__divmod__('s')
NotImplemented RustPython: >>>>> (12).__divmod__('s')
Traceback (most recent call last):
File <stdin>, line 0, in <module>
TypeError: Cannot divmod power 'int' object and 'str' object While some others just have implementation when they probably shouldn’t. Eg. comparing anything to CPython: >>> (12).__eq__('s')
NotImplemented RustPython: >>>>> (12).__eq__('s')
False This makes it impossible to implement custom types that can be equal to built-in ones, eg. in CPython: >>> class Foo:
... def __init__(self, payload):
... self.payload = payload
... def __eq__(self, other):
... return self.payload == other
...
>>> Foo(3) == 3
True
>>> 3 == Foo(3)
True So there is going to be some work needed cleaning all the methods… |
Uh oh!
There was an error while loading. Please reload this page.
The contract for binary methods such as
__add__
,__eq__
, etc. is such that they are expected to returnNotImplemented
error to signal lack of support for a particular type, in which case the interpreter will try flipping the operands, and finally fall back to object comparison (in the case of==
).I believe that
VirtualMachine::call_or_unsupported
isRustPython
's implementation of this behavior, but instead of using theNotImplemented
built-in constant, it expects implementors to raise aNotImplementedError
. This can be seen by calling the magic methods directly:RustPython:
CPython:
This was discovered in #410.
The text was updated successfully, but these errors were encountered: