|
1 | 1 | from collections.abc import Iterator |
2 | 2 | from types import GenericAlias |
3 | | -from typing import Any, Literal, TypeVar, final, overload |
| 3 | +from typing import Any, Generic, Literal, TypeVar, final, overload |
4 | 4 | from typing_extensions import TypeForm |
5 | 5 |
|
6 | 6 | _T = TypeVar("_T") |
7 | 7 |
|
8 | 8 | @final |
9 | 9 | class Template: # TODO: consider making `Template` generic on `TypeVarTuple` |
10 | 10 | strings: tuple[str, ...] |
11 | | - interpolations: tuple[Interpolation, ...] |
| 11 | + interpolations: tuple[Interpolation[Any], ...] |
12 | 12 |
|
13 | | - def __new__(cls, *args: str | Interpolation) -> Template: ... |
14 | | - def __iter__(self) -> Iterator[str | Interpolation]: ... |
| 13 | + def __new__(cls, *args: str | Interpolation[Any]) -> Template: ... |
| 14 | + def __iter__(self) -> Iterator[str | Interpolation[Any]]: ... |
15 | 15 | def __add__(self, other: Template, /) -> Template: ... |
16 | 16 | def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ... |
17 | 17 | @property |
18 | 18 | def values(self) -> tuple[Any, ...]: ... # Tuple of interpolation values, which can have any type |
19 | 19 |
|
20 | 20 | @final |
21 | | -class Interpolation: |
22 | | - value: Any # TODO: consider making `Interpolation` generic in runtime |
| 21 | +class Interpolation(Generic[_T]): |
| 22 | + value: _T |
23 | 23 | expression: str |
24 | 24 | conversion: Literal["a", "r", "s"] | None |
25 | 25 | format_spec: str |
26 | 26 |
|
27 | 27 | __match_args__ = ("value", "expression", "conversion", "format_spec") |
28 | 28 |
|
29 | 29 | def __new__( |
30 | | - cls, value: Any, expression: str = "", conversion: Literal["a", "r", "s"] | None = None, format_spec: str = "" |
31 | | - ) -> Interpolation: ... |
| 30 | + cls, value: _T, expression: str = "", conversion: Literal["a", "r", "s"] | None = None, format_spec: str = "" |
| 31 | + ) -> Interpolation[_T]: ... |
32 | 32 | def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ... |
33 | 33 |
|
34 | 34 | @overload |
|
0 commit comments