`Literal` accepted as `type[T]`, and is inconsistent
from typing import Literal, TypeGuard, TypeVar
T = TypeVar("T")
def isa_literal(obj: object, t: type[T]) -> TypeGuard[T]:
assert False
a = isa_literal("string", Literal["string"]) # Argument of type "type[Literal['string']]" cannot be assigned to parameter "t" of type "type[T@isa_literal]" in function "isa_literal"basedpyright[reportArgumentType](https://github.com/detachhead/basedpyright/blob/main/docs/configuration.md#reportArgumentType)
a = isa_literal("string", Literal["string", "other_string"])
The first one fails, although, to my knowledge, it's a valid construct.
Edit
When the value goes through a generic function, it has a different type than just the direct assignment:
from typing import Literal
def f[T](t: T) -> T: ...
c: type[int]
c = Literal[1, 2] # Expression of type "type[Literal[1, 2]]" cannot be assigned to declared type "type[int]"
c = f(Literal[1, 2])
Neither Literal["a"] nor Literal["a", "b"] are values of type type[T] ('classes'). They are TypeForms, which are undenotable in Python.
Both should show an error here.
def f[T](t: type[T]):
t.mro()
f(Literal[1, "a"])
i think neither should be an error and type should work with all types. maybe this can be addressed as part of #123
An instance of _LiteralGenericAlias is not a class (type)
Does basedpyright support TypeForm? Maybe with some flag?
No, unfortunately not, see #123