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 dataclasses import dataclass | |
| @dataclass | |
| class Example: | |
| a: int | |
| __name__: str | |
| e = Example(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
| import random | |
| def foo() -> None: | |
| a: float | str | |
| a = random.random() | |
| a = input() |
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 | |
| import types | |
| from typing import Any | |
| def _validate_type_hint(parameter_type: type[Any]) -> tuple[str, Any] | None: | |
| generic_args: tuple[type[Any], ...] = typing.get_args(parameter_type) | |
| match generic_args: | |
| case () | (_,): |
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 show_count(count, word): | |
| if count == 1: | |
| return f'1 {word}' | |
| count_str = str(count) if count else 'no' | |
| return f'{count_str} {word}s' | |
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 Callable | |
| def f(x: str)->None: | |
| if isinstance(x, int): | |
| print("impossible") |
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
| class A: | |
| def __new__(cls) -> int: | |
| return 42 | |
| reveal_type(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
| class A: | |
| def go(self) -> None: | |
| pass | |
| class B0: | |
| X: type[A] | None = None | |
| class B(B0): | |
| X = 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 Callable, TypeVar | |
| _K = TypeVar("_K") | |
| _V = TypeVar("_V") | |
| class Foo: | |
| pass | |
| class Util: |
NewerOlder