-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
The contract for binary methods such as __add__, __eq__, etc. is such that they are expected to return NotImplemented 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 is RustPython's implementation of this behavior, but instead of using the NotImplemented built-in constant, it expects implementors to raise a NotImplementedError. This can be seen by calling the magic methods directly:
RustPython:
>>>>> (3).__sub__('')
Traceback (most recent call last):
File <unknown>, line 0, in <module>
NotImplementedError: Cannot substract 'int' object and 'str' object
CPython:
>>> (3).__sub__('')
NotImplemented
This was discovered in #410.
Metadata
Metadata
Assignees
Labels
No labels