Repository navigation
Multiple lines f-string with non-ASCII breaks tokenize.generate_tokens in 3.12.4 #120343
Copy link
Copy link
Closed
Closed
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
import io
import tokenize
src = '''\
a = f"""
Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli"""
'''
tokens = list(tokenize.generate_tokens(io.StringIO(src).readline))
for token in tokens:
print(token)
assert tokens[4].start == (2, 68), tokens[4].startPython 3.12.3 (correct)
❯ python --version
Python 3.12.3
❯ python c.py
TokenInfo(type=1 (NAME), string='a', start=(1, 0), end=(1, 1), line='a = f"""\n')
TokenInfo(type=55 (OP), string='=', start=(1, 2), end=(1, 3), line='a = f"""\n')
TokenInfo(type=61 (FSTRING_START), string='f"""', start=(1, 4), end=(1, 8), line='a = f"""\n')
TokenInfo(type=62 (FSTRING_MIDDLE), string='\n Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli', start=(1, 8), end=(2, 68), line='a = f"""\n Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli"""\n')
TokenInfo(type=63 (FSTRING_END), string='"""', start=(2, 68), end=(2, 71), line=' Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli"""\n')
TokenInfo(type=4 (NEWLINE), string='\n', start=(2, 71), end=(2, 72), line=' Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli"""\n')
TokenInfo(type=0 (ENDMARKER), string='', start=(3, 0), end=(3, 0), line='')Python 3.12.4 (broken)
❯ python --version
Python 3.12.4
❯ python c.py
TokenInfo(type=1 (NAME), string='a', start=(1, 0), end=(1, 1), line='a = f"""\n')
TokenInfo(type=55 (OP), string='=', start=(1, 2), end=(1, 3), line='a = f"""\n')
TokenInfo(type=61 (FSTRING_START), string='f"""', start=(1, 4), end=(1, 8), line='a = f"""\n')
TokenInfo(type=62 (FSTRING_MIDDLE), string='\n Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli', start=(1, 8), end=(2, 68), line='a = f"""\n Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli"""\n')
TokenInfo(type=63 (FSTRING_END), string='"""', start=(2, 72), end=(2, 75), line=' Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli"""\n')
TokenInfo(type=4 (NEWLINE), string='\n', start=(2, 75), end=(2, 76), line=' Autorzy, którzy tą jednostkę mają wpisani jako AKTUALNA -- czyli"""\n')
TokenInfo(type=0 (ENDMARKER), string='', start=(3, 0), end=(3, 0), line='')
Traceback (most recent call last):
File "/private/tmp/flake8/c.py", line 13, in <module>
assert tokens[4].start == (2, 68), tokens[4].start
^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: (2, 72)More info
I found previous similar issue here: #112943
CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
- gh-120343: Do not reset byte_col_offset_diff after multiline tokens #120352
- [3.13] gh-120343: Do not reset byte_col_offset_diff after multiline tokens (GH-120352) #120355
- [3.12] gh-120343: Do not reset byte_col_offset_diff after multiline tokens (GH-120352) #120356
- gh-120343: Fix column offsets of multiline tokens in tokenize #120391
- [3.13] gh-120343: Fix column offsets of multiline tokens in tokenize (GH-120391) #120427
- [3.12] gh-120343: Fix column offsets of multiline tokens in tokenize (GH-120391) #120428
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
pablogsal commentedon Jun 11, 2024
Bisected to:
@lysnikolaou do you have time to take a look?
lysnikolaou commentedon Jun 11, 2024
Yeah, this really seemed like it would be related to that commit. Will have a look in a tiny bit!
pablogsal commentedon Jun 11, 2024
It seems that is always the f-string end
pythongh-120343: Do not reset byte_col_offset_diff after multiline to…
gh-120343: Do not reset byte_col_offset_diff after multiline tokens (#…
pythongh-120343: Do not reset byte_col_offset_diff after multiline to…
pythongh-120343: Do not reset byte_col_offset_diff after multiline to…
[3.12] gh-120343: Do not reset byte_col_offset_diff after multiline t…
[3.13] gh-120343: Do not reset byte_col_offset_diff after multiline t…
lysnikolaou commentedon Jun 11, 2024
Fixed.
1 remaining item
pythongh-120343: Fix column offsets of multiline tokens in tokenize
gh-120343: Fix column offsets of multiline tokens in tokenize (#120391)
pythongh-120343: Fix column offsets of multiline tokens in tokenize (p…
pythongh-120343: Fix column offsets of multiline tokens in tokenize (p…
[3.12] gh-120343: Fix column offsets of multiline tokens in tokenize (G…
[3.13] gh-120343: Fix column offsets of multiline tokens in tokenize (G…
lysnikolaou commentedon Jun 12, 2024
Closing again. Hopefully everything is resolved now. Feel free to reopen in case something weird shows up again.
pythongh-120343: Do not reset byte_col_offset_diff after multiline to…
pythongh-120343: Fix column offsets of multiline tokens in tokenize (p…
pythongh-120343: Do not reset byte_col_offset_diff after multiline to…
pythongh-120343: Fix column offsets of multiline tokens in tokenize (p…
pythongh-120343: Do not reset byte_col_offset_diff after multiline to…
pythongh-120343: Fix column offsets of multiline tokens in tokenize (p…