diff --git a/Misc/NEWS.d/next/Library/2026-05-22-01-18-01.gh-issue-150207.je1B0Y.rst b/Misc/NEWS.d/next/Library/2026-05-22-01-18-01.gh-issue-150207.je1B0Y.rst new file mode 100644 index 000000000000000..ebf57db806f62ca --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-22-01-18-01.gh-issue-150207.je1B0Y.rst @@ -0,0 +1,4 @@ +Set a :exc:`MemoryError` via :c:func:`PyErr_NoMemory` when buffer allocation + fails in the tokenizer's ``_PyTokenizer_translate_newlines`` helper, so the + out-of-memory condition is propagated as a proper Python exception instead + of only being recorded in ``tok->done``. diff --git a/Parser/tokenizer/helpers.c b/Parser/tokenizer/helpers.c index 9542969ad3127b9..32064909ebba01f 100644 --- a/Parser/tokenizer/helpers.c +++ b/Parser/tokenizer/helpers.c @@ -221,6 +221,7 @@ _PyTokenizer_translate_newlines(const char *s, int exec_input, int preserve_crlf buf = PyMem_Malloc(needed_length); if (buf == NULL) { tok->done = E_NOMEM; + PyErr_NoMemory(); return NULL; } for (current = buf; *s; s++, current++) {