Skip to content

Instantly share code, notes, and snippets.

@takwas
Created August 18, 2020 14:14
Show Gist options
  • Save takwas/0a13946c01cf20a9874342d4e56bd8c9 to your computer and use it in GitHub Desktop.
Save takwas/0a13946c01cf20a9874342d4e56bd8c9 to your computer and use it in GitHub Desktop.
from typing import Type, Union
class BaseType:
pass
class EvenType:
pass
class OddType:
pass
def func(num: Union[int, str], return_type_spec: Type[BaseType]) -> BaseType:
try:
if num % 2 == 0:
return EvenType()
return OddType()
except TypeError:
return BaseType()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment