Skip to content

Multiple lines f-string with non-ASCII breaks tokenize.generate_tokens in 3.12.4 #120343

Closed

Description

@leemars

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].start

Python 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

Activity

  1. lysnikolaou commented on Jun 12, 2024

    @lysnikolaou
    Member

    I found one more issue after looking into #120377, so I'm reopening this. I'll push a fix shortly.

  2. added 2 commits that reference this issue on Jun 12, 2024
  3. added 2 commits that reference this issue on Jun 12, 2024
  4. added 2 commits that reference this issue on Jun 12, 2024
  5. lysnikolaou commented on Jun 12, 2024

    @lysnikolaou
    Member

    Closing again. Hopefully everything is resolved now. Feel free to reopen in case something weird shows up again.

  6. added 2 commits that reference this issue on Jun 30, 2024
  7. added 2 commits that reference this issue on Jul 11, 2024
  8. added 2 commits that reference this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions