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