microsoft / microsoft/pyright

Numpy dtype.names seen as None

Open
#11,528 7 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

```python3
import numpy as np

_DTYPE = np.dtype([("id", np.int32), ("name", np.str_, 16)])

for n in _DTYPE.names:
print(n)
```

I get on the `for` line: **Object of type "None" cannot be used as iterable value**

names is not None and it does print "id\nname" as expected.

pyright version: 1.1.411

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Python and NumPy reproducer with Pyright 1.1.411, then trace how dtype.names is typed and checked at the for line. Done means Pyright no longer reports that names may be None while preserving correct diagnostics for genuinely optional iterables.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.