Skip to content

Commit dcd221f

Browse files
committed
Moar tests and fix location error
1 parent 67a0239 commit dcd221f

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

Lib/test/test_tokenize.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,6 @@ def test_string(self):
421421
FSTRING_MIDDLE '}' (1, 9) (1, 10)
422422
FSTRING_END '"' (1, 11) (1, 12)
423423
""")
424-
# TODO: I don't think is is correct now (ERRORTOKEN)
425-
# self.check_tokenize('f"{1+1"', """\
426-
# FSTRING_START 'f"' (1, 0) (1, 2)
427-
# ERRORTOKEN '{' (1, 2) (1, 3)
428-
# FSTRING_END '"' (1, 3) (1, 4)
429-
# """)
430424
self.check_tokenize('f"""{f\'\'\'{f\'{f"{1+1}"}\'}\'\'\'}"""', """\
431425
FSTRING_START 'f\"""' (1, 0) (1, 4)
432426
OP '{' (1, 4) (1, 5)
@@ -447,6 +441,26 @@ def test_string(self):
447441
FSTRING_END "'''" (1, 24) (1, 27)
448442
OP '}' (1, 27) (1, 28)
449443
FSTRING_END '\"""' (1, 28) (1, 31)
444+
""")
445+
self.check_tokenize('f""" x\nstr(data, encoding={invalid!r})\n"""', """\
446+
FSTRING_START 'f\"""' (1, 0) (1, 4)
447+
FSTRING_MIDDLE ' x\\nstr(data, encoding=' (1, 4) (2, 19)
448+
OP '{' (2, 19) (2, 20)
449+
NAME 'invalid' (2, 20) (2, 27)
450+
OP '!' (2, 27) (2, 28)
451+
NAME 'r' (2, 28) (2, 29)
452+
OP '}' (2, 29) (2, 30)
453+
FSTRING_MIDDLE ')\\n' (2, 30) (3, 0)
454+
FSTRING_END '\"""' (3, 0) (3, 3)
455+
""")
456+
self.check_tokenize('f"""123456789\nsomething{None}bad"""', """\
457+
FSTRING_START 'f\"""' (1, 0) (1, 4)
458+
FSTRING_MIDDLE '123456789\\nsomething' (1, 4) (2, 9)
459+
OP '{' (2, 9) (2, 10)
460+
NAME 'None' (2, 10) (2, 14)
461+
OP '}' (2, 14) (2, 15)
462+
FSTRING_MIDDLE 'bad' (2, 15) (2, 18)
463+
FSTRING_END '\"""' (2, 18) (2, 21)
450464
""")
451465
self.check_tokenize('f"""abc"""', """\
452466
FSTRING_START 'f\"""' (1, 0) (1, 4)

Parser/tokenizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ tok_underflow_interactive(struct tok_state *tok) {
11261126

11271127
static int
11281128
tok_underflow_file(struct tok_state *tok) {
1129-
if (tok->start == NULL) {
1129+
if (tok->start == NULL && !INSIDE_FSTRING(tok)) {
11301130
tok->cur = tok->inp = tok->buf;
11311131
}
11321132
if (tok->decoding_state == STATE_INIT) {

0 commit comments

Comments
 (0)