Skip to content

Conversation

lucascolley
Copy link
Member

No description provided.

@lucascolley
Copy link
Member Author

@jorenham any advice for the NumPy dtype typing failures that have appeared upon upgrading mypy?

@lucascolley
Copy link
Member Author

and dtype is np.float32
and
if library is Backend.CUPY and dtype is np.float32:

@lucascolley lucascolley added the maintenance general maintenance label Sep 26, 2025
@lucascolley lucascolley added this to the 0.9.1 milestone Sep 26, 2025
@jorenham
Copy link
Member

@jorenham any advice for the NumPy dtype typing failures that have appeared upon upgrading mypy?

You're comparing a np.dtype instance using is with a type[np.float32], which indeed is always false. You probably want to instead do dtype.type is np.float32

@lucascolley
Copy link
Member Author

@jorenham any advice for the NumPy dtype typing failures that have appeared upon upgrading mypy?

You're comparing a np.dtype instance using is with a type[np.float32], which indeed is always false. You probably want to instead do dtype.type is np.float32

So the problem is that we're annotating np.float32 with np.dtype[Any]? How are we supposed to type that?

@jorenham
Copy link
Member

@jorenham any advice for the NumPy dtype typing failures that have appeared upon upgrading mypy?

You're comparing a np.dtype instance using is with a type[np.float32], which indeed is always false. You probably want to instead do dtype.type is np.float32

So the problem is that we're annotating np.float32 with np.dtype[Any]? How are we supposed to type that?

is dtype an instance of np.dtype, e.g. dtype=np.dtype("float32")', or is is a scalar type like dtype=np.float32?

@lucascolley
Copy link
Member Author

A scalar type.

@lucascolley
Copy link
Member Author

@jorenham
Copy link
Member

A scalar type.

Ah ok, then

dtype: np.dtype[Any],

should instead be dtype: type[np.generic] or dtype: type[np.floating] or something like that

@jorenham
Copy link
Member

jorenham commented Sep 27, 2025

BTW, hypothesis also has a dedicated strategy for this: https://hypothesis.readthedocs.io/en/latest/reference/strategies.html#hypothesis.extra.numpy.floating_dtypes

It's for np.dtypes though :P

@lucascolley
Copy link
Member Author

Sounds like we should use that then!

@lucascolley
Copy link
Member Author

thanks, I think 11d5472 should do it

@lucascolley lucascolley merged commit 33e3888 into data-apis:main Sep 27, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance general maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants