mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Optional static typing for Python

Results 1055 mypy issues
Sort by recently updated
recently updated
newest added

```python def foobar(foo: Union[str, float]): if foo in ['fizz', 'buzz']: reveal_type(foo) else: pass ``` The revealed type is `Union[builtins.str, builtins.float]` but should be `builtins.str`

feature
priority-1-normal
topic-type-narrowing

**Bug Report** If a `@contextmanager` yields a generic type alias, mypy 1.11 errors with `Argument 1 to "contextmanager" has incompatible type "$TYPE"; expected "$TYPE" [arg-type]`, where the inferred and expected...

bug
topic-type-variables
topic-usability

```py from typing import Generic, TypeVar T = TypeVar("T", covariant=True) class Foo(Generic[T]): def b(self, value: T | int) -> None: ... # no error ``` [playground](https://mypy-play.net/?mypy=latest&python=3.12&flags=show-error-codes%2Cstrict%2Ccheck-untyped-defs%2Cdisallow-any-decorated%2Cdisallow-any-expr%2Cdisallow-any-explicit%2Cdisallow-any-generics%2Cdisallow-any-unimported%2Cdisallow-incomplete-defs%2Cdisallow-subclassing-any%2Cdisallow-untyped-calls%2Cdisallow-untyped-decorators%2Cdisallow-untyped-defs%2Cno-implicit-reexport%2Clocal-partial-types%2Cwarn-redundant-casts%2Cwarn-return-any%2Cwarn-unreachable%2Cwarn-unused-configs%2Cwarn-unused-ignores&gist=7e1cc2b01f160335b2927f781bb1c6fe)

bug

```py # mypy: enable-incomplete-feature=NewGenericSyntax # mypy: disable-error-code=empty-body from typing import Generic, TypeVar class Contravariant[T]: def fn(self, value: T) -> None: ... class Foo[T]: def fn(self) -> Contravariant[T]: ... def call_foo_with_string(foo:...

bug

This PR adds special handling for `typing.get_args` when the input is a `Union[Literal...]` allowing it to return that type instead of the current behavior of returning `Any`. Adds the handling...

I went with an option (instead of an error code), because the was no specific error for this code. I reuse existing rules / codes. The only change is a...

**Bug Report** `partial` support is too fragile and easy to fool. **To Reproduce** ```python import typing as t from functools import partial # 1. # uncomment this to get type...

bug

**Feature** The `bug` function below has a bug: the `else` branch will execute both when `x` is None and when it is empty, and the latter is unexpected. The programmer...

feature

Fixed #17892 This is a sketch of an implementation of a check that catches bugs like ```python def bug(x: None | str): if x: print(f"the str value is {x}") else:...

I'm not super sure if this is a bug or not, but the behavior is different in Mypy and pyright so probably worth discussing it. **To Reproduce** https://mypy-play.net/?mypy=latest&python=3.12&gist=3a34812b38b40ca5cb913ee48daf2c49 ```python from...

feature
topic-enum
affects-mypyc