Skip to content

tokenize.py: NEWLINE/NL mixup after line continuation character in indented blockΒ #106202

Closed as not planned
@lysnikolaou

Description

@lysnikolaou

Bug report

There's the following difference in behavior between 3.11 and 3.12.

cpython on ξ‚  main via C v14.0.3-clang via 🐍 pyenv 3.11.3 
❯ cat tmp/t.py         
def f():
  x = 0
  \
  %                                                                                                                                                                             

cpython on ξ‚  main via C v14.0.3-clang via 🐍 pyenv 3.11.3 
❯ ../cpython-versions/3.11.3/build/bin/python3.11 -m tokenize tmp/t.py 
0,0-0,0:            ENCODING       'utf-8'        
1,0-1,3:            NAME           'def'          
1,4-1,5:            NAME           'f'            
1,5-1,6:            OP             '('            
1,6-1,7:            OP             ')'            
1,7-1,8:            OP             ':'            
1,8-1,9:            NEWLINE        '\n'           
2,0-2,2:            INDENT         '  '           
2,2-2,3:            NAME           'x'            
2,4-2,5:            OP             '='            
2,6-2,7:            NUMBER         '0'            
2,7-2,8:            NEWLINE        '\n'           
4,2-4,3:            NEWLINE        ''             
5,0-5,0:            DEDENT         ''             
5,0-5,0:            ENDMARKER      ''             

cpython on ξ‚  main via C v14.0.3-clang via 🐍 pyenv 3.11.3 
❯ ./python.exe -m tokenize tmp/t.py                                   
0,0-0,0:            ENCODING       'utf-8'        
1,0-1,3:            NAME           'def'          
1,4-1,5:            NAME           'f'            
1,5-1,6:            OP             '('            
1,6-1,7:            OP             ')'            
1,7-1,8:            OP             ':'            
1,8-1,9:            NEWLINE        '\n'           
2,0-2,2:            INDENT         '  '           
2,2-2,3:            NAME           'x'            
2,4-2,5:            OP             '='            
2,6-2,7:            NUMBER         '0'            
2,7-2,8:            NEWLINE        '\n'           
4,2-4,3:            NL             ''             <-- This used to be a NEWLINE
5,0-5,0:            DEDENT         ''             
5,0-5,0:            ENDMARKER      ''             

I tend to believe that the previous NEWLINE was correct, but I'm not sure. Keep in mind, this breaks some tests on IPython. What do you think?

cc @pablogsal @mgmacias95

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions