basedmypy
basedmypy copied to clipboard
Fix `type`
type has a lot of whackyness, this issue can collect all the strange things it does.
a = type # error: Expression type contains "Any" (has type "type[type]") [misc]
# this is because the type is being inferred as the constructor, not an alias, which contains Any
from typing import TypeAlias
t: TypeAlias = type
a1: t[int] # main.py:4: error: "type" expects no type arguments, but 1 given [type-arg]
a2: t # no error
l: TypeAlias = list
b1: l[int] # no error
b2: l # error: Missing type parameters for generic type "t" [type-arg]
from typing import _T as T, Callable, TypeVar
def f(f: Callable[[object], T]) -> T: ...
reveal_type(f(type)) # type
# I think what's happening here is that it's a hole in the special casing
Maybe there are two kinds of type, the generic one and the non generic one. you would think that the ungeneric one should be deleted.
Maybe the only special case we need is type[type], where the inner type doesn't need to specify the type var.