Skip to content

Conflation of NotImplemented and NotImplementedError #419

@OddCoincidence

Description

@OddCoincidence

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions