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

[numpy] mypy does not raise type-var when NDArray with incompatible dtype is used as a generic. #17228

Open
randolf-scholz opened this issue May 8, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@randolf-scholz
Copy link
Contributor

randolf-scholz commented May 8, 2024

To Reproduce

import numpy as np
from numpy.typing import NDArray

class A: ...

def foo() -> NDArray[A]:  # ✅ raises type-var (true positive)
    return np.array([A()])

def bar() -> list[NDArray[A]]:  # ❌ does not raise type-var (false negative)
    return [np.array([A()])]

Expected Behavior

mypy should raise error: Type argument "A" of "NDArray" must be a subtype of "generic" [type-var] in both instances.

Your Environment

  • Mypy version used: 1.10
  • numpy version: 1.26.4
  • Mypy configuration options: plugins = ["numpy.typing.mypy_plugin"]
  • Python version used: 3.11.7
@randolf-scholz randolf-scholz added the bug mypy got something wrong label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant