Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created April 11, 2021 03:07
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 podhmo/ff56783d7db3be4868e7f265ba9c5773 to your computer and use it in GitHub Desktop.
Save podhmo/ff56783d7db3be4868e7f265ba9c5773 to your computer and use it in GitHub Desktop.
from typing import TypedDict
class ParamsDict(TypedDict):
name: str
params : ParamsDict = {"nam": "foo"}
from typing import TypedDict
from mypy_extensions import Expand
# https://github.com/python/mypy/issues/4441
class ParamsDict(TypedDict):
name: str
def greet(prefix: str, *, name: str) -> None:
print(f"{prefix}, {name}")
def hello(**params: Expand[ParamsDict]) -> None:
greet("hello", **params)
hello(nam="foo")
from typing import overload, Any, TYPE_CHECKING
def greet(prefix: str, *, name: str) -> None:
print(f"{prefix}, {name}")
@overload
def hello(*, name: str) -> None:
...
# suppress "Single overload definition, multiple required"
@overload
def hello(*, _: object = ...) -> None:
...
def hello(**params: Any) -> None:
greet("hello", **params)
hello(name="foo")
hello(nam="x")
from typing import Any
def greet(prefix: str, *, name: str) -> None:
print(f"{prefix}, {name}")
def hello(**params: Any) -> None:
greet("hello", **params)
hello(nam="foo")
MYPY := mypy --pretty --strict
00:
$(MYPY) $(shell echo $@*.py)
01:
$(MYPY) $(shell echo $@*.py)
02:
$(MYPY) $(shell echo $@*.py)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment