Skip to content

TYP: inplace arithmetic erroneously suggests that __ifloordiv__ is supported for complex128 #28957

@MarcoGorelli

Description

@MarcoGorelli

Describe the issue:

Type hints suggests that inplace floor division is supported for complex arrays, but it raises at runtime

Reproduce the code example:

import numpy as np
from typing import Any

def func(a: np.ndarray[Any, np.dtype[np.complex128]]) -> None:
    a //= 2

func(np.array([1 + 2j]))

Error message:

No error when type checking

But, at runtime:

TypeError: ufunc 'floor_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Python and NumPy Versions:

2.2.5
3.12.5 (main, Aug 14 2024, 05:08:31) [Clang 18.1.8 ]

Type-checker version and settings:

pyright 1.1.398

Additional typing packages.

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions