Skip to content

Instantly share code, notes, and snippets.

@pauleveritt
Created January 16, 2021 22:05
Show Gist options
  • Save pauleveritt/112cc444d4be24c005629fdcb50bdc8e to your computer and use it in GitHub Desktop.
Save pauleveritt/112cc444d4be24c005629fdcb50bdc8e to your computer and use it in GitHub Desktop.
from dataclasses import dataclass
from typing import Protocol, Optional, TypeVar, Type
class Animal(Protocol):
name: str
@dataclass
class Mammal:
name: str
lookup_types = {Animal: Mammal}
T = TypeVar('T')
def main(lookup_type: Type[T]) -> Optional[Type]:
lt = lookup_type.get(lookup_type)
return lt
main(lookup_type=Animal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment