Created
July 28, 2020 20:29
-
-
Save podhmo/fc74f85f1800a6bad80c4b9f7b1ed955 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
def hello(name: str) -> None: | |
pass |
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_extensions import Annotated | |
class Description: | |
def __init__(self, description: str) -> None: | |
self.description = description | |
def hello(*, name: Annotated[str, Description("the name of person")]) -> None: | |
print(f"hello {name}") |
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_extensions import Annotated | |
class Description: | |
def __init__(self, description: str) -> None: | |
self.description = description | |
def hello(*, name: Annotated[str, Description("the name of person")]) -> None: | |
reveal_type(name) | |
print(f"hello {name}") |
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_extensions import Annotated | |
class Description: | |
def __init__(self, description: str) -> None: | |
self.description = description | |
def hello(*, name: Annotated[str, Description("the name of person")]) -> None: | |
print(f"hello {name}") | |
if __name__ == "__main__": | |
from typing_extensions import get_type_hints | |
print(get_type_hints(hello)) | |
# {'name': <class 'str'>, 'return': <class 'NoneType'>} | |
print(get_type_hints(hello, include_extras=True)) | |
# {'name': typing_extensions.Annotated[str, <__main__.Description object at 0x10cd1e730>], 'return': <class 'NoneType'>} | |
from typing_extensions import get_args, get_origin | |
hints = get_type_hints(hello, include_extras=True) | |
print(get_args(hints["name"])) | |
# (<class 'str'>, <__main__.Description object at 0x106427730>) | |
print(get_origin(hints["name"])) | |
# <class 'typing_extensions.Annotated'> |
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_extensions import Annotated | |
class Description: | |
def __init__(self, description: str) -> None: | |
self.description = description | |
def hello(*, name: Annotated[str, Description("the name of person")]) -> None: | |
print(f"hello {name}") | |
if __name__ == "__main__": | |
from typing_extensions import get_type_hints | |
hints = get_type_hints(hello, include_extras=True) | |
import typing_inspect | |
print(typing_inspect.get_args(hints["name"])) | |
# (<class 'str'>,) | |
print(hasattr(hints["name"], "__metadata__")) | |
# True | |
print(hints["name"].__metadata__) | |
# (<__main__.Description object at 0x104b9b730>,) |
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
PY_FILE = $(shell echo $@*.py) | |
00: | |
mypy --strict $(PY_FILE) | |
01: | |
mypy --strict $(PY_FILE) | |
02: | |
diff -u 01*.py 02*.py || exit 0 | |
mypy --strict $(PY_FILE) | |
setup: | |
python -m pip install -r requirements.txt | |
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
typing-extensions | |
typing-inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment