Skip to content

Commit bfc7ab3

Browse files
sobolevnmingyu.park
authored andcommitted
Add string.templatelib in 3.14 (python#14044)
1 parent 47093e2 commit bfc7ab3

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

stdlib/@tests/stubtest_allowlists/py314.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ sre_compile.CH_NEGATE
111111
sre_constants.CH_NEGATE
112112
sre_parse.CH_NEGATE
113113
string.Template.flags
114-
string.templatelib
115114
sys.is_remote_debug_enabled
116115
sys.remote_exec
117116
tarfile.TarFile.zstopen

stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ ssl: 3.0-
283283
stat: 3.0-
284284
statistics: 3.4-
285285
string: 3.0-
286+
string.templatelib: 3.14-
286287
stringprep: 3.0-
287288
struct: 3.0-
288289
subprocess: 3.0-
File renamed without changes.

stdlib/string/templatelib.pyi

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from collections.abc import Iterator
2+
from typing import Any, Literal, final
3+
4+
__all__ = ["Interpolation", "Template"]
5+
6+
@final
7+
class Template: # TODO: consider making `Template` generic on `TypeVarTuple`
8+
strings: tuple[str, ...]
9+
interpolations: tuple[Interpolation, ...]
10+
11+
def __new__(cls, *args: str | Interpolation) -> Template: ...
12+
def __iter__(self) -> Iterator[str | Interpolation]: ...
13+
def __add__(self, other: Template | str) -> Template: ...
14+
@property
15+
def values(self) -> tuple[Any, ...]: ... # Tuple of interpolation values, which can have any type
16+
17+
@final
18+
class Interpolation:
19+
value: Any # TODO: consider making `Interpolation` generic in runtime
20+
expression: str
21+
conversion: Literal["a", "r", "s"] | None
22+
format_spec: str
23+
24+
__match_args__ = ("value", "expression", "conversion", "format_spec")
25+
26+
def __new__(
27+
cls, value: Any, expression: str, conversion: Literal["a", "r", "s"] | None = None, format_spec: str = ""
28+
) -> Interpolation: ...

0 commit comments

Comments
 (0)