The following type does not currently get identified as optional:
Optional[Union[int, float]]
This is because the code is looking for type(None) as the second value in the __args__ array but does not take into account the flattening of Union types (Optional is an alias of Union[T, type(None)]).
The following type does not currently get identified as optional:
This is because the code is looking for
type(None)
as the second value in the__args__
array but does not take into account the flattening ofUnion
types (Optional
is an alias ofUnion[T, type(None)]
).