This file contains hidden or 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
| import typing | |
| class _Int(int): | |
| _min: typing.ClassVar[int] | |
| _max: typing.ClassVar[int] | |
| _code: typing.ClassVar[str] | |
| def __new__(cls, value: int) -> _Int: |
This file contains hidden or 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 Protocol, Any | |
| class Result: | |
| def __init__(self, foo): | |
| self.foo = foo | |
| class MyInterface(Protocol): |
This file contains hidden or 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 Protocol, Any | |
| class Result: | |
| pass | |
| class MyInterface(Protocol): | |
| def foo(self) -> Result: ... |
This file contains hidden or 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 Optional | |
| class Node: | |
| data: int | |
| left: Optional[Node] | |
| right: Optional[Node] | |
| def __init__(self, data: int)-> None: |
This file contains hidden or 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 Optional | |
| class Node: | |
| data: int | |
| left: Optional[Node] | |
| right: Optional[Node] | |
| def __init__(self, data: int)-> None: |
This file contains hidden or 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 TD1(TypedDict): | |
| a: int | |
| b: str | |
| class TD2(TypedDict): | |
| a: str | |
| c: int |
This file contains hidden or 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 TD1(TypedDict): | |
| a: int | |
| b: str | |
| class TD2(TypedDict): | |
| a: str | |
| c: int |
This file contains hidden or 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 Callable | |
| add_one: Callable[[int], int] = lambda x: x + 1 | |
| add_two: Callable[[int], int] = lambda x: str(x) |
This file contains hidden or 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 Iterator | |
| def fib(n: int) -> Iterator[int]: | |
| a, b = 0, 1 | |
| while a < n: | |
| yield a | |
| a, b = b, a + b | |
This file contains hidden or 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 __future__ import annotations | |
| import typing as ty | |
| if ty.TYPE_CHECKING: | |
| import numpy as np | |
| def foo(bar: list | np.ndarray[tuple[int]]) -> list: | |
| return [] |
NewerOlder