KotlinIsland / basedtyping

Runtime components for use with basedmypy
MIT License
7 stars 1 forks source link

Support passing old union types to `issubform` #16

Open github-actions[bot] opened 2 years ago

github-actions[bot] commented 2 years ago

https://github.com/KotlinIsland/basedtyping/blob/997af522c978e0a5254cfcfe0ab3070219f432ab/tests/test_is_subform.py#L21


from typing import Union

from basedtyping import issubform

assert issubform(
    Union[int, str],  # type: ignore[arg-type]
    Union[str, int],  # type: ignore[arg-type]
)

31dba085975f5e1e859c0c7c076f040fd35ce713

KotlinIsland commented 2 years ago

Update typeshed to make Union[X, Y] return something unique instead of object. Then update the type annotation on issubform to include that.

KotlinIsland commented 10 months ago

Maybe this is a basedmypy issue. The problem is that Union is just an instance of _SpecialForm, and we don't have any concept of an 'instance type'. Union[X] returns an instance of a _UnionGenericAlias, but that's not something that we want to expose I think, and we couldn't anyway without the aforementioned instance type.

I suggest, in the lack of instance type support, we special case it in basedmypy.

KotlinIsland commented 10 months ago

Unless we like, and say that _SpecialForm is generic, then we could keep track of it's type!