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 dataclasses import dataclass | |
@dataclass | |
class Test: | |
text: str | |
@staticmethod | |
def gen_text() -> Text: | |
return Test("some text") |
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 Iterator | |
def fib(n: int) -> Iterator[int]: | |
a, b = 0, 1 | |
while a < n: | |
yield a | |
a, b = b, a + b | |
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 Generic, TypeVar | |
T = TypeVar("T", contravariant=True) | |
class N(Generic[T]): ... | |
class C(N[N["C"]]): ... | |
x: N[C] = C() |
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 * | |
from pathlib import Path | |
T = TypeVar("T") | |
def reverse_directory_search(filename: str, search_base: Path) -> Optional[Path]: | |
"""Search backwards for a file starting on a given directory. | |
E.g.: from /a/b/c a file d.txt will be checked in the following order: | |
- /a/b/c/d.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
from typing import Any, Generic, TypeVar | |
_T = TypeVar("_T") | |
_U = TypeVar("_U", covariant=True) | |
class Node(Generic[_T, _U]): | |
children: "dict[str, Node[_U, object]]" | |
def __init__(self, children: "dict[str, Node[_U, object]]"): | |
self.children = children |
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 Callable | |
def dec(f) -> Callable[[int], None]: raise NotImplementedError | |
if int(): | |
def f(x: str): pass | |
else: | |
@dec | |
def f() -> 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 import Literal | |
from typing_extensions import assert_never | |
def doit_if(result: Literal[1, -1]) -> None: | |
if result == 1: | |
pass | |
elif result == -1: | |
reveal_type(result) | |
else: |
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 ( | |
Generic, | |
TypeVar, | |
Callable, | |
Concatenate, | |
ParamSpec, | |
reveal_type, | |
) | |
from dataclasses import dataclass |
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 ( | |
Generic, | |
TypeVar, | |
Callable, | |
Concatenate, | |
ParamSpec, | |
reveal_type, | |
) | |
from dataclasses import dataclass |
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 Tuple | |
child_min_max: Tuple[int, int] = (0, 0) |
NewerOlder