Closed
Description
In preparation for strict checking of None
values, Optional[T]
should be an alias for Union[T, None]
(for arbitrary T
).
There are at least two valid ways to implement this:
- Special case
Optional[T]
in the semantic analyzer. - Support generic type aliases of form
Optional = Union[T, None]
, and use this to defineOptional
.
In the latter case, the fact that Optional
takes a type argument would be inferred from the right hand side -- I assume that T
is a free (unbound) type variable, so it is inferred as an argument of the left hand side. The second case is also complicated by the fact that the result of Union[...]
should support indexing.
The first approach is okay as well, even though eventually we might want generic type aliases.
In either case, the typing
module must be modified as well so that Optional
can be used at runtime.