Closed
Description
As of #2302 mypy accepts use of a type application of a generic class as an expression anywhere. Previously, such applications were only allowed in type aliases (i.e., on the RHS of a simple assignment). But there is still special logic for such aliases, and it creates unexpected Any
types. (They were there before too, but now there's clearly no reason for them.)
from typing import TypeVar, Generic
T = TypeVar('T')
class C(Generic[T]): pass
reveal_type(C[int]())
# before 2302: Generic type is prohibited as a runtime expression (use a type alias or '# type:' comment)
# : Revealed type is 'Any'
# after 2302: Revealed type is 'index.C[builtins.int*]'
c = C[int]
x = c()
reveal_type(x)
# both before and after 2302: Revealed type is 'Any'
# (Even c has type Any.)