Skip to content

Commit 0935371

Browse files
committed
fixup! fixup! fixup! fixup! pythongh-105069: Add a readline-like callable to the tokenizer to consume input iteratively
1 parent 2d6f0a6 commit 0935371

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Lib/test/test_tokenize.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ def gen():
6464
with self.assertRaises(TypeError):
6565
list(generate_tokens(gen().__next__))
6666

67+
def gen():
68+
yield "sdfosdg"
69+
1/0
70+
with self.assertRaises(ZeroDivisionError):
71+
list(generate_tokens(gen().__next__))
72+
6773
def test_implicit_newline(self):
6874
# Make sure that the tokenizer puts in an implicit NEWLINE
6975
# when the input lacks a trailing new line.

Parser/tokenizer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ static char *
140140
error_ret(struct tok_state *tok) /* XXX */
141141
{
142142
tok->decoding_erred = 1;
143-
if (tok->fp != NULL && tok->buf != NULL) /* see _PyTokenizer_Free */
143+
if ((tok->fp != NULL || tok->readline != NULL) && tok->buf != NULL) {/* see _PyTokenizer_Free */
144144
PyMem_Free(tok->buf);
145+
}
145146
tok->buf = tok->cur = tok->inp = NULL;
146147
tok->start = NULL;
147148
tok->end = NULL;

0 commit comments

Comments
 (0)