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 | |
| def iterator() -> typing.Iterator[int]: | |
| x = yield 10 | |
| # The `Iterator` return type here is a supertype of `Generator`. | |
| # It has no "send" type, nor a send method, so this should always be `None` | |
| reveal_type(x) # revealed: 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
| def foo() -> int: | |
| raise Exception() | |
| def optional_import_func(): | |
| try: | |
| x = foo() | |
| except ImportError: | |
| pass | |
| print(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 TypedDict | |
| @abc | |
| @efg.hij | |
| @klm[nop] | |
| @qrs.tuv[wxy] | |
| class A(TypedDict): | |
| 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 overload, Callable | |
| @overload | |
| def decorator[T](cls: type[T], /, *, extra: int = 0) -> type[T]: | |
| ... | |
| @overload | |
| def decorator[T](cls: None = None, /, *, extra: int = 0) -> Callable[[type[T]], type[T]]: | |
| ... |
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 Never, Protocol, reveal_type | |
| class ReturnsT[T](Protocol): | |
| def get(self) -> T: ... | |
| class ReturnsNever: | |
| def get(self) -> Never: | |
| raise RuntimeError | |
| def through_protocol[T](x: ReturnsT[T]) -> T: |
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) -> 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
| print() |
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 Hard: | |
| pass | |
| class Soft: | |
| pass | |
| lst: list[Hard] | list[Soft] | |
| lst = [val for val in lst] |
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 Hard: | |
| pass | |
| class Soft: | |
| pass | |
| lst: list[Hard] | list[Soft] | |
| lst = [val for val in lst] |
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 | |
NewerOlder