Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optype.numpy.To{}ND false negatives in mypy #194

Closed
jorenham opened this issue Nov 24, 2024 · 1 comment · Fixed by #196
Closed

optype.numpy.To{}ND false negatives in mypy #194

jorenham opened this issue Nov 24, 2024 · 1 comment · Fixed by #196

Comments

@jorenham
Copy link
Owner

jorenham commented Nov 24, 2024

@pavyamsiri discovered in jorenham/scipy-stubs#195 (comment) a false negative in mypy with recursive sequences. This causes e.g. onp.ToFloatND = "huh" to be accepted by mypy.

I raised this in python/mypy#18184.

In the meantime we'll need a workaround, as this directly affects a very large portion of the annotations in scipy-stubs.

@jorenham jorenham self-assigned this Nov 24, 2024
@jorenham jorenham added this to the v0.7.2 milestone Nov 24, 2024
@jorenham
Copy link
Owner Author

import numpy._typing as _npt
import optype.numpy as onp

def f_np(x: _npt._ArrayLikeFloat_co) -> None: ...
def f_onp(x: onp.ToFloatND) -> None: ...

f_np("duck")  # OK: rejected
f_onp("duck")  # FAIL: accepted (mypy only; pyright rejects)

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

Successfully merging a pull request may close this issue.

1 participant