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 Any, Generic, Protocol, TypeVar | |
| from typing_extensions import override | |
| T = TypeVar("T") | |
| class Just(Protocol, Generic[T]): | |
| # we did use explicit override but mypy does not see it | |
| @property # type: ignore[override] | |
| @override |
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 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 collections.abc import Sequence, Hashable | |
| class DataFrame: | |
| def __setitem__( | |
| self, key: tuple[slice, Hashable], value: Sequence[int] | |
| ) -> None: ... | |
| # mypy and ty error, pyrefly and pyright pass | |
| DataFrame().__setitem__((slice(None, None, None), iter([0])), [1]) | |
| DataFrame()[:, iter([0])] = [1] |
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 Literal | |
| def signed(sign: Literal[-1,1], num: float) -> float: | |
| return sign * num | |
| assert signed(1, 3) == 3 | |
| assert signed(-1, 3) == -3 |
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: float) -> Iterator[int]: | |
| a, b = 0, 1 | |
| while a < n: | |
| yield a | |
| a, b = b, a + b | |
| for zahl in fib(10): | |
| print(zahl) |
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
| def _combine_tuple[*T](*args: *T) -> tuple[*T]: | |
| return args | |
| def foo(): | |
| bla = _combine_tuple(1, "foo", 6) |
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, reveal_type | |
| def asdf[T](fn: Callable[[T], T]) -> Callable[[T], T]: ... | |
| @asdf | |
| def foo[T](value: T) -> T: ... | |
| reveal_type(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
| from typing import assert_never, TypeAlias, TypeGuard | |
| A: TypeAlias = int | str | None | |
| B: TypeAlias = A | complex | |
| def _is_a(t: object) -> TypeGuard[A]: | |
| return isinstance(t, (str, int)) or t is None | |
| def f(t: B) -> object: |
NewerOlder