Skip to content

float64 does not respect __rmul__() protocol #17650

@ElieGouzien

Description

@ElieGouzien

float64 does not respect __rmul__() protocol and does unexpected things instead.
I didn't test, but it might be similar for the other operators.

Reproducing code example:

import numpy as np
x = np.float64(2)
x * (1,)

raises a TypeError (expected), while __mul__((1,)) correctly returns NotImplemented.


import numpy as np
class Test(tuple):
    def __rmul__(self, other):
        return None
x = np.float64(2)
x * Test((1,))

returns array([2]), what is not correct (None is the expected result).
On the contrary, 2 * Test((1,)) correctly returns None.

NumPy/Python version information:

python: 3.8.2
numpy: 1.19.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions