Skip to content

Commit 6a7b448

Browse files
PEP 750 bug and spec fix (python#58)
* Bugfix: increment `interpolationsidx` in `template_new()` * Spec fix: don't return empty strings from `templateiter_next()` --------- Co-authored-by: Lysandros Nikolaou <[email protected]>
1 parent bb7359a commit 6a7b448

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Objects/templateobject.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ templateiter_next(templateiterobject *self)
2222
PyObject *item;
2323
if (self->from_strings) {
2424
item = PyIter_Next(self->stringsiter);
25+
self->from_strings = 0;
26+
if (PyUnicode_GET_LENGTH(item) == 0) {
27+
Py_SETREF(item, PyIter_Next(self->interpolationsiter));
28+
self->from_strings = 1;
29+
}
2530
} else {
2631
item = PyIter_Next(self->interpolationsiter);
32+
self->from_strings = 1;
2733
}
28-
self->from_strings = !self->from_strings;
2934
return item;
3035
}
3136

@@ -133,7 +138,7 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
133138
if (!last_was_str) {
134139
PyTuple_SET_ITEM(strings, stringsidx++, &_Py_STR(empty));
135140
}
136-
PyTuple_SET_ITEM(interpolations, interpolationsidx, Py_NewRef(item));
141+
PyTuple_SET_ITEM(interpolations, interpolationsidx++, Py_NewRef(item));
137142
last_was_str = 0;
138143
}
139144
}

0 commit comments

Comments
 (0)