File tree 3 files changed +34
-4
lines changed
3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change 15
15
import unittest
16
16
from test import support
17
17
from test .support .os_helper import temp_cwd
18
- from test .support .script_helper import assert_python_failure
18
+ from test .support .script_helper import assert_python_failure , assert_python_ok
19
19
20
20
a_global = 'global variable'
21
21
@@ -1635,5 +1635,17 @@ def test_syntax_error_after_debug(self):
1635
1635
"f'{1=}{1;}'" ,
1636
1636
])
1637
1637
1638
+ def test_debug_in_file (self ):
1639
+ with temp_cwd ():
1640
+ script = 'script.py'
1641
+ with open ('script.py' , 'w' ) as f :
1642
+ f .write (f"""\
1643
+ print(f'''{{
1644
+ 3
1645
+ =}}''')""" )
1646
+
1647
+ _ , stdout , _ = assert_python_ok (script )
1648
+ self .assertEqual (stdout , b"\n 3\n =3\n " )
1649
+
1638
1650
if __name__ == '__main__' :
1639
1651
unittest .main ()
Original file line number Diff line number Diff line change @@ -558,6 +558,19 @@ def test_string(self):
558
558
OP '}' (1, 39) (1, 40)
559
559
FSTRING_MIDDLE ' final words' (1, 40) (1, 52)
560
560
FSTRING_END "'" (1, 52) (1, 53)
561
+ """ )
562
+ self .check_tokenize ("""\
563
+ f'''{
564
+ 3
565
+ =}'''""" , """\
566
+ FSTRING_START "f'''" (1, 0) (1, 4)
567
+ OP '{' (1, 4) (1, 5)
568
+ NL '\\ n' (1, 5) (1, 6)
569
+ NUMBER '3' (2, 0) (2, 1)
570
+ NL '\\ n' (2, 1) (2, 2)
571
+ OP '=' (3, 0) (3, 1)
572
+ OP '}' (3, 1) (3, 2)
573
+ FSTRING_END "'''" (3, 2) (3, 5)
561
574
""" )
562
575
563
576
def test_function (self ):
Original file line number Diff line number Diff line change @@ -1039,9 +1039,6 @@ tok_readline_raw(struct tok_state *tok)
1039
1039
if (line == NULL ) {
1040
1040
return 1 ;
1041
1041
}
1042
- if (tok -> tok_mode_stack_index && !update_fstring_expr (tok , 0 )) {
1043
- return 0 ;
1044
- }
1045
1042
if (tok -> fp_interactive &&
1046
1043
tok_concatenate_interactive_new_line (tok , line ) == -1 ) {
1047
1044
return 0 ;
@@ -1270,6 +1267,10 @@ tok_underflow_file(struct tok_state *tok) {
1270
1267
tok -> implicit_newline = 1 ;
1271
1268
}
1272
1269
1270
+ if (tok -> tok_mode_stack_index && !update_fstring_expr (tok , 0 )) {
1271
+ return 0 ;
1272
+ }
1273
+
1273
1274
ADVANCE_LINENO ();
1274
1275
if (tok -> decoding_state != STATE_NORMAL ) {
1275
1276
if (tok -> lineno > 2 ) {
@@ -1314,6 +1315,10 @@ tok_underflow_readline(struct tok_state* tok) {
1314
1315
tok -> implicit_newline = 1 ;
1315
1316
}
1316
1317
1318
+ if (tok -> tok_mode_stack_index && !update_fstring_expr (tok , 0 )) {
1319
+ return 0 ;
1320
+ }
1321
+
1317
1322
ADVANCE_LINENO ();
1318
1323
/* The default encoding is UTF-8, so make sure we don't have any
1319
1324
non-UTF-8 sequences in it. */
You can’t perform that action at this time.
0 commit comments