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 abc import ABC, abstractmethod | |
| from dataclasses import dataclass | |
| from typing import Collection | |
| @dataclass | |
| class PreparedTask[I, R, O]: | |
| input: I | |
| reference: R | |
| grader: Grader[I, R, O] |
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 | |
| def foo(x: int, y): | |
| z: str = 0 # at least one param annotation, body is checked | |
| reveal_type(x + y) # y treated as Any | |
| def bar(x: int, y: int): | |
| z: str = 0 # all params annotated, body is checked | |
| reveal_type(x + y) | |
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 Callable | |
| from typing import Protocol | |
| def x() -> Callable[[int], str]: | |
| return lambda a: str(reveal_type(a)) | |
| class A(Protocol): | |
| def __call__(self, a: int) -> 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
| # mypy: enable-incomplete-feature=TypeForm | |
| from typing import Annotated, Any, TypeVar, overload | |
| from typing_extensions import assert_type, TypeForm | |
| T = TypeVar("T") | |
| @overload | |
| def convert(value: Any) -> Any: | |
| ... |
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 | |
| def foo() -> list[str]: | |
| result = [] | |
| for i in range(0, 10): | |
| result.append(str(i)) | |
| reveal_type(result) | |
| return result |
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_type | |
| import random | |
| cond = random.randint(0, 1) | |
| if cond: | |
| def zip(*args) -> list[int]: | |
| return [] | |
| def f(a: list[int], b: list[int]): | |
| assert_type(zip([1], [2]), list[int]) |
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 PmbArgs: | |
| hook: int = 123 | |
| def install_hook(hook: str) -> None: | |
| print(f"Installing {hook}") | |
| args = PmbArgs() | |
| install_hook(getattr(args, "hook")) |
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 Sequence | |
| vals: Sequence[int] = (1,2,3) | |
| reveal_type(vals) |
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(o: object) -> None: | |
| assert isinstance(o, list) | |
| def bar(o: object) -> None: | |
| foo(o) # Ensures that o is a list | |
| print(o[0]) |
NewerOlder