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 Concatenate, Callable | |
| def foo[**P](fn: Callable[P, None], x: int, *args: P.args, **kwargs: P.kwargs) -> None: ... | |
| def test(a: str) -> None: ... | |
| foo(fn=test, x=1, a="") |
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 NodeA: | |
| def __init__(self: Self) -> None: | |
| reveal_type(self) # Self`0 | |
| self.myself: Self = self # ✅️ | |
| class NodeB: | |
| def __init__(self) -> None: | |
| reveal_type(self) # __main__.NodeB |
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, Self | |
| class FloatScalar[FloatT](Protocol): | |
| def pow(self, arg: FloatT) -> Self: ... | |
| def upcast(arg: FloatScalar[object]) -> FloatScalar[float]: | |
| return arg # ✅️ |
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, Self | |
| class FloatScalar[FloatT](Protocol): | |
| def pow(self, arg: FloatT) -> Self: ... | |
| def upcast(arg: FloatScalar[object]) -> FloatScalar[float]: | |
| return arg # ✅️ |
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, Self | |
| class FloatScalar[FloatT](Protocol): | |
| def pow(self, arg: FloatT) -> Self | complex: ... | |
| def upcast(arg: FloatScalar[object]) -> FloatScalar[float]: | |
| return arg |
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 | |
| from typing import Generator, AsyncGenerator | |
| def async_returns_generator() -> Generator[int, int, None] | AsyncGenerator[int, int]: | |
| x = yield 1 | |
| reveal_type(x) | |
| return 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 Protocol, TypedDict, Unpack, Any | |
| class Factory(Protocol): | |
| def __call__(self, **kwargs: Any) -> Any: | |
| pass | |
| def use_factory(factory: Factory): | |
| pass |
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, TypedDict, Unpack, Any | |
| class Factory(Protocol): | |
| def __call__(self, **kwargs: Any) -> Any: | |
| pass | |
| def use_factory(factory: Factory): | |
| pass |
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 unittest.mock import Mock | |
| class O: ... | |
| def take_o(o: O) -> None: ... | |
| take_o(Mock()) |
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 Iterable, Protocol | |
| from dataclasses import dataclass | |
| @dataclass | |
| class Square: | |
| sidelength: float | |
| def area(self) -> float: | |
| return self.sidelength * self.sidelength |
NewerOlder