Skip to content

Conversation

@jorenham
Copy link
Member

@jorenham jorenham commented Aug 26, 2025

ported from numpy/numtype#692


Long story short; this is why:

>>> np.int8.__init__.__qualname__
'object.__init__'
>>> np.int8.__new__.__qualname__
'int8.__new__'

@jorenham jorenham added the numtype Isssue/PR related to numpy/numtype label Aug 26, 2025
@github-actions
Copy link

Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code:

xarray (https://github.com/pydata/xarray)
+ xarray/namedarray/dtypes.py: note: In function "maybe_promote":
+ xarray/namedarray/dtypes.py:86: error: Too many arguments for "generic"  [call-arg]

@jorenham
Copy link
Member Author

jorenham commented Aug 27, 2025

Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code:

xarray (https://github.com/pydata/xarray)
+ xarray/namedarray/dtypes.py: note: In function "maybe_promote":
+ xarray/namedarray/dtypes.py:86: error: Too many arguments for "generic"  [call-arg]

Relevant code: https://github.com/pydata/xarray/blob/98732e76481bdf5c497a030657cff32db134e27d/xarray/namedarray/dtypes.py#L48-L86

This new primer error is a true positive. They're calling dtype_out.type(fill_value) with dtype_out: np.dtype[np.generic]. Type-checkers will interpret that as np.generic(fill_value).
It's easy to fix by using np.dtype instead of np.dtype[np.generic] in the function signature. A generic-typing approach could also work, but would be more involved.

@charris charris merged commit 46709e8 into numpy:main Sep 5, 2025
78 checks passed
@charris
Copy link
Member

charris commented Sep 5, 2025

Thanks Joren. IIUC, it is up to xarray to fix the problem.

@jorenham
Copy link
Member Author

jorenham commented Sep 6, 2025

IIUC, it is up to xarray to fix the problem.

That's right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

41 - Static typing numtype Isssue/PR related to numpy/numtype

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants