Allow using IntEnums in NDArray type definitions
- Dominant language
- Python
- Stars
- 15.6k
- Forks
- 1.8k
- Avg merge
- 12h 13m
- Merged PRs (30d)
- 52
Description
If you have a question about a behavior that you’re seeing in pyright, consider posting to the [Pyright discussion forum](https://github.com/microsoft/pyright/discussions).
**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 `IntEnum`s to numpy arrays, I would like indicate the specific `IntEnum` in typehints.
However, this results in a error.
example:
```python
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.
Contributor guide
Research direction
Start with the provided IntEnum and numpy.typing.NDArray reproducer, then trace Pyright's handling of NDArray type-argument specialization and the generic[Any] diagnostic. Done means the example type-checks without reportInvalidTypeForm while preserving existing NDArray validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100