basedmypy
basedmypy copied to clipboard
Support for `ReifiedGeneric`s
Reified Generics in basedtyping need special casing in basedmypy.
isinstance and issubclass:
class Foo(ReifiedGeneric[T]): ...
isinstance(Foo[int](), Foo[int])
Ban TypeVars:
def foo(t: T):
a: ReifiedList[T] # should be an error
mypy doesnt need to be changed to accommodate for the ReifiedGenerics i'm adding to basedtyping
actually it does, since isinstance and issubclass have hardcoded functionality in mypy so we need to add logic to not show this error if it's a ReifiedGeneric
isinstance(Reified[int, str](), Reified[int, str]) # Parameterized generics cannot be used with class or instance checks [misc]
i was originally going to makeour own is_instance function using a TypeGuard
_T_type = TypeVar("_T_type", bound=type)
@overload
def is_instance(__obj: object, __class_or_tuple: _T_type) -> TypeGuard[_T_type]:
...
@overload
def is_instance(
__obj: object,
__class_or_tuple: UnionType | tuple[type | UnionType | tuple[object, ...], ...],
) -> bool:
...
def is_instance(
__obj: object,
__class_or_tuple: type
| UnionType
| tuple[type | UnionType | tuple[object, ...], ...],
) -> bool:
return isinstance(__obj, __class_or_tuple)
but that didn't work due to https://github.com/python/mypy/issues/11428
I think modifying mypy checks are much better idea than making a typeguard
perhaps, but i prefer using existing functionality instead of intrinsic hidden behavior where possible. the fact that isinstance and issubclass don't even use TypeGuards seems very sus to me
imo TypeGuards are really broken atm and the intrinsic behavior is much better, so until typeguards are fixed I wouldn't bother.