Last active
September 7, 2018 14:43
-
-
Save mbarkhau/d8fc85bfa0a3918d53954654be545c20 to your computer and use it in GitHub Desktop.
kinds_of_namedtuple_parameters.py
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
# copied as literally as possible from here | |
# https://mypy.readthedocs.io/en/latest/kinds_of_types.html#the-type-of-class-objects | |
from typing import NamedTuple, TypeVar, Type | |
class Env(NamedTuple): | |
log_level: str = "DEBUG" | |
N = TypeVar("N", bound=NamedTuple) | |
def getenv(env_type: Type[N]) -> N: | |
return env_type(...) | |
env = getenv(Env) | |
# $ mypy | |
# src/myenv/__init__.py:18: error: Value of type variable "N" of "getenv" cannot be "Env" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment