Skip to content

gh-151238: Check for _get_resized_exprs failure in _PyPegen_{joined,template}_str#151259

Open
StanFromIreland wants to merge 1 commit into
python:mainfrom
StanFromIreland:_get_resized_exprs
Open

gh-151238: Check for _get_resized_exprs failure in _PyPegen_{joined,template}_str#151259
StanFromIreland wants to merge 1 commit into
python:mainfrom
StanFromIreland:_get_resized_exprs

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Jun 10, 2026

Copy link
Copy Markdown
Member

There are several cases where _get_resized_exprs can fail and return NULL (all of which are quite rare, however):

const char* quote_str = PyBytes_AsString(a->bytes);
if (quote_str == NULL) {
return NULL;
}

if (asdl_seq_LEN(values) != 2) {
PyErr_Format(PyExc_SystemError,
string_kind == TSTRING
? "unexpected TemplateStr node without debug data in t-string at line %d"
: "unexpected JoinedStr node without debug data in f-string at line %d",
item->lineno);
return NULL;

asdl_expr_seq *seq = _Py_asdl_expr_seq_new(total_items, p->arena);
if (seq == NULL) {
return NULL;
}

resized_exprs = _Py_asdl_expr_seq_new(index, p->arena);
if (resized_exprs == NULL) {
return NULL;
}

And the one triggered by the reproducer in the issue (which I test):

item = _PyPegen_decode_fstring_part(p, is_raw, item, b);
if (item == NULL) {
return NULL;
}

_PyPegen_decode_fstring_part returns NULL because it calls _PyPegen_decode_string which in turn calls warn_invalid_escape_sequence which triggers the failure as it tries to import modules to issue a warning, but gets a TypeError.

@StanFromIreland StanFromIreland changed the title Check for _get_resized_exprs failure in _PyPegen_{joined,template}_str gh-151238: Check for _get_resized_exprs failure in _PyPegen_{joined,template}_str Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant