mypy
mypy copied to clipboard
Optional static typing for Python
This code tries to import `TypeAlias` from `typing` if possible and falls back to `typing_extensions` if it isn't available (e.g. on Python 3.8): ```py try: from typing import TypeAlias #...
**Background** I'm using a helper type definition from a stubs package in project. I'll call it `MyHelperType` here (if it matters, it's actually `StrOrPromise` from [django-stubs](https://github.com/typeddjango/django-stubs)). We have two deployment...
**Crash Report** Checking the following minimal example with `mypy` causes it to crash with an `IndexError`: ```Python from typing import Callable class Message: pass Handler = Callable[[Message], None] VecHandler =...
```py class A: a: A | None a: A | None a = A() while a := a.a: # error: Item "None" of "A | None" has no attribute "a"...
Fixes #12364 When matching a tuple to a sequence pattern, this change narrows the type of tuple items inside the matched case: ```py def test(a: bool, b: bool) -> None:...
**Bug Report** Code of a certain form causes a false positive error: ``` error: Overloaded function signatures 1 and 2 overlap with incompatible return types [misc] ``` **To Reproduce** Gist:...
**Feature** If one specifies an error code twice, `mypy` allows it: ```python foo = 1 foo = "hi" # type: ignore[assignment,assignment] ``` **Pitch** Can we add an opt-in rule to...
**Bug Report** When iterating over a `Tuple` with mixed types, mypy infers the element type based on the lowest common denominator, rather than a `Union` of element types. Mypy's behavior...
```py from typing import TypeVar, Callable T = TypeVar("T") class A: def __init__(self, a: int) -> None: ... def foo(t: type[T]) -> T: return t() foo(A) # SUS ALERT! ```
**Bug Report** I can't really describe the bug well, but hopefully the gist below illustrates it. I'm attempting to go from a list of `Callable`s that includes types (e.g. `int`,...