Skip to content

Commit 623436b

Browse files
committed
Implement a reverse pairs, why not?
1 parent ae17d24 commit 623436b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pep/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,17 @@ def pairs(template: Template) -> t.Iterator[tuple[InterpolationProto | None, str
116116
yield None, template.args[0]
117117
for i, s in zip(template.args[1::2], template.args[2::2]):
118118
yield i, s
119+
120+
121+
def pairs_s_i(template: Template) -> t.Iterator[tuple[str, Interpolation | None]]:
122+
"""
123+
Yield pairs of strings and interpolations from a template.
124+
125+
This allows us to experiment with the structure of a template;
126+
it is the *opposite* of Guido's pairs() proposal as discussed here:
127+
128+
https://discuss.python.org/t/pep750-template-strings-new-updates/71594/65
129+
"""
130+
for s, i in zip(template.args[::2], template.args[1::2]):
131+
yield s, i
132+
yield template.args[-1], None

0 commit comments

Comments
 (0)