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 enum import Enum | |
| from typing import reveal_type | |
| class NoValue(Enum): | |
| FIRST = "first" | |
| def command(self) -> str: | |
| reveal_type(self.value) | |
| return "--" + self.value | |
| class WithValue(Enum): |
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, reveal_type | |
| def get() -> Any: | |
| return 42 # pretend this could be anything | |
| x = get() | |
| reveal_type(x) | |
| y = get() | |
| assert isinstance(y, 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 Any | |
| def do_something_awesome(thing: list[str | dict[Any, Any]]): | |
| ... | |
| only_list_str: list[str] = ["foo", "bar"] | |
| list_mixed: list[str, dict[Any, Any]] = ["foo", {"bar": "baz"}] | |
| do_something_awesome(["foo", "bar"]) |
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, Annotated | |
| class A(): | |
| def __init__(self: Annotated[Self]): | |
| 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 TypeVar, Literal, Generic, overload, reveal_type | |
| from typing import Any | |
| _ST = TypeVar("_ST") | |
| _GT = TypeVar("_GT") | |
| class Field(Generic[_ST, _GT]): | |
| def __init__(self, *, null: bool = False) -> None: | |
| super().__init__() |
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 __future__ import annotations | |
| from dataclasses import dataclass | |
| from contextvars import ContextVar, copy_context | |
| from typing import Generic, TypeVar, overload, reveal_type | |
| T = TypeVar("T") | |
| class CtxProperty(Generic[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
| x = [] | |
| x.append(2) | |
| x.append("test") |
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 abc | |
| import collections.abc | |
| import logging | |
| import typing | |
| import uuid | |
| logger = logging.getLogger(__name__) | |
| class GenericRegistry[K, V](abc.ABC, collections.abc.Mapping[K, V]): |
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 pathlib import Path | |
| def split_paths(paths: str) -> list[Path]: | |
| paths: list[str] = paths.split(":") | |
| return [Path(p) for p in paths] |
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 | |
| from typing_extensions import TypeAliasType | |
| @dataclass | |
| class A: | |
| T1 = TypeAliasType("T1", int) | |
| x: A.T1 = 2 |
NewerOlder