import polars as pl
def as_polars_type[T: pl.DataType](x: Any, required: T) -> T:
if isinstance(x, required): # required is red-underlined by type checker
return x
else:
raise Exception(f"{x} is not of type {required}")
This does not correctly typecheck for me using Pylance + Pyright:
Argument of type "T@as_polars_type" cannot be assigned to parameter "class_or_tuple" of type "_ClassInfo" in function "isinstance"
Type "T@as_polars_type" is incompatible with type "_ClassInfo"
"DataType*" is incompatible with "type"
"DataType*" is incompatible with "UnionType"
"DataType*" is incompatible with "tuple[_ClassInfo, ...]"
What can I fix?