Open DetachHead opened 2 years ago
_Final
_BaseGenericAlias
_GenericAlias
_collect_type_vars
_tp_cache
_type_convert
_alias
Literal
Union
a = Union[int, str]
What is this value? It can be extremely confusing that it is an instance of _SpecialForm.
_SpecialForm
Union is an instance of _SpecialForm. _SpecialForm.__getitem__ returns a _SpecialForm, but each instance is specialized in this method.
_SpecialForm.__getitem__
Unions __getitem__ returns an instance of _UnionGenericAlias which is a proxy object to Union that stores the type parameters.
__getitem__
_UnionGenericAlias
I would both be useful and help with understanding if these objects were typed in a nice way.
functional benefit:
def f(u: TypeForm[Union[T]) -> tuple[T]: ... a = f(Union[str, int]) # a is tuple[T]
understanding benefit:
reveal_type(Union) # TypeForm[Union[str, int]] reveal_type(Union[str, int]) # TypeForm[Union[str, int]]
There needs to be discussion around the exact impl, as I am unsure.
Also these are tightly special cased and would probably need fixing in mypy.
KotlinIsland/basedmypy/issues/24
_Final
_BaseGenericAlias
_GenericAlias
_collect_type_vars
_tp_cache
_type_convert
_alias
Literal
Union
What is this value? It can be extremely confusing that it is an instance of
_SpecialForm
.Union
is an instance of_SpecialForm
._SpecialForm.__getitem__
returns a_SpecialForm
, but each instance is specialized in this method.Union
s__getitem__
returns an instance of_UnionGenericAlias
which is a proxy object toUnion
that stores the type parameters.I would both be useful and help with understanding if these objects were typed in a nice way.
functional benefit:
understanding benefit:
There needs to be discussion around the exact impl, as I am unsure.
Also these are tightly special cased and would probably need fixing in mypy.