python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.5k stars 2.83k forks source link

no `Any` errors when type inferred from value passed to `type[T]` with no type arguments #14861

Open DetachHead opened 1 year ago

DetachHead commented 1 year ago
from typing import cast, TypeVar, Any

T = TypeVar("T")

def get_value(type_: type[T]) -> T:
    ...

foo = get_value(list) # no error
bar: list # correct error (Missing type parameters for generic type "list"  [type-arg])

reveal_type(foo[0]) # no error
reveal_type(bar[0]) # correct error (Expression type contains "Any" (has type "List[Any]")  [misc])

playground

ankm20 commented 1 year ago

Would this be a good first issue to explore? Can this issue be assigned to me?