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 ast | |
| class ComparisonSwapper(ast.NodeTransformer): | |
| OP_MAP = { | |
| ast.Lt: ast.GtE, | |
| ast.GtE: ast.Lt, | |
| } | |
| def visit_Compare(self, node: ast.AST) -> ast.AST: | |
| new_ops = [self.OP_MAP.get(type(op), type(op))() for op in node.ops] |
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 functools import cached_property | |
| class Foo: | |
| def awesome(self): | |
| ... | |
| class Bar: | |
| @cached_property | |
| def client(self) -> Foo: | |
| return Foo() |
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
| class Shape: | |
| def area(self) -> float: | |
| return 1.0 | |
| class Circle(Shape): | |
| def radius(self) -> float: | |
| return 2.0 | |
| # T is constrained to be Shape or a subclass of Shape | |
| def total_area[T: Shape](shapes: tuple[T, ...]) -> float: |
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 | |
| from typing import ReadOnly | |
| from typing import Required | |
| class GitParameters_A(TypedDict, total=False): | |
| git_projectcollection_url: str | |
| git_commit_hash: str | |
| git_branch: str | |
| git_repository_id: Required[str] |
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, Iterable, Protocol, Concatenate, overload | |
| class Transformer[P, B]: | |
| pass | |
| @overload | |
| def partial_transformer[T1, T2, T3, T4, **P, O](func: Callable[Concatenate[T1, T2, T3, T4, P], O]) -> Callable[P, Transformer[tuple[T1, T2, T3, T4], O]]: | |
| pass | |
| @overload |
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 typing import reveal_type | |
| class C: | |
| def __new__(cls): | |
| reveal_type(cls) | |
| return super().__new__(cls) |
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 Self, reveal_type | |
| class C: | |
| def __new__(cls) -> Self: | |
| reveal_type(cls) | |
| return super().__new__(cls) |
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 numpy as np | |
| import pandas as pd | |
| from sklearn.ensemble import RandomForestClassifier | |
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 NamedTuple, TypeVar | |
| T = TypeVar("T") | |
| GenericPoint = NamedTuple("GenericPoint", [("x", T), ("y", T)]) | |
| def _(p: GenericPoint[int]): | |
| reveal_type(p[0]) | |
| reveal_type(p[1]) | |
| reveal_type(p.x) |
NewerOlder