Skip to content

Instantly share code, notes, and snippets.

@mbarkhau
Last active September 7, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbarkhau/d8fc85bfa0a3918d53954654be545c20 to your computer and use it in GitHub Desktop.
Save mbarkhau/d8fc85bfa0a3918d53954654be545c20 to your computer and use it in GitHub Desktop.
kinds_of_namedtuple_parameters.py
# 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