Skip to content

Allow using IntEnums in NDArray type definitions #11386

@TomvdPoll

Description

@TomvdPoll

If you have a question about a behavior that you’re seeing in pyright, consider posting to the Pyright discussion forum.

Is your feature request related to a problem? Please describe.
I use both numpy arrays and IntEnums for my project. Since python is perfectly fine with assigning IntEnums to numpy arrays, I would like indicate the specific IntEnum in typehints.

However, this results in a error.

example:

from enum import IntEnum
from numpy.typing import NDArray


class MyIntEnum(IntEnum):
    OPTION_A = 0
    OPTION_B = 1
    OPTION_C = 2


def function_using_array_of_enums(arr: NDArray[MyIntEnum]):
    ...

results in the following error:

error: Could not specialize type "NDArray[_ScalarT@NDArray]"
    Type "MyIntEnum" is not assignable to type "generic[Any]"
      "MyIntEnum" is not assignable to "generic[Any]" (reportInvalidTypeForm)

Describe the solution you’d like
I would like to be able to typehint my code in the example mentioned above, since it allows for a much cleaner and more readable type hint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions