Created
April 11, 2021 03:07
-
-
Save podhmo/ff56783d7db3be4868e7f265ba9c5773 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 typing import TypedDict | |
class ParamsDict(TypedDict): | |
name: str | |
params : ParamsDict = {"nam": "foo"} |
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 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") | |
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 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") |
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 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") |
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
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