In 3.5, I was able to test for optional and parameter types by:
from typing import Union, Optional
def is_optional(t):
return issubclass(type(None), t)
def is_valid(e, t):
return issubclass(type(e), t)
is_optional(Union[int, str])
> False
is_optional(Union[int, str, None])
> True
is_valid("abc", Union[int, str])
> True
is_valid(["abc"], Union[int, str])
> False
The issubclass method is no longer allowed in 3.6. How do I accomplish the equivalent in 3.6 on?
In 3.5, I was able to test for optional and parameter types by:
The issubclass method is no longer allowed in 3.6. How do I accomplish the equivalent in 3.6 on?