Created
January 16, 2021 22:05
-
-
Save pauleveritt/112cc444d4be24c005629fdcb50bdc8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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