Skip to content
Prev Previous commit
Next Next commit
fixup! fixup! fixup! fixup! gh-105069: Add a readline-like callable t…
…o the tokenizer to consume input iteratively
  • Loading branch information
pablogsal committed May 30, 2023
commit 0935371e6648ba69287108072e056eb4e63195ac
6 changes: 6 additions & 0 deletions Lib/test/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def gen():
with self.assertRaises(TypeError):
list(generate_tokens(gen().__next__))

def gen():
yield "sdfosdg"
1/0
with self.assertRaises(ZeroDivisionError):
list(generate_tokens(gen().__next__))

def test_implicit_newline(self):
# Make sure that the tokenizer puts in an implicit NEWLINE
# when the input lacks a trailing new line.
Expand Down
3 changes: 2 additions & 1 deletion Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ static char *
error_ret(struct tok_state *tok) /* XXX */
{
tok->decoding_erred = 1;
if (tok->fp != NULL && tok->buf != NULL) /* see _PyTokenizer_Free */
if ((tok->fp != NULL || tok->readline != NULL) && tok->buf != NULL) {/* see _PyTokenizer_Free */
PyMem_Free(tok->buf);
}
tok->buf = tok->cur = tok->inp = NULL;
tok->start = NULL;
tok->end = NULL;
Expand Down