FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

untokenize() round-trip fails for t-strings (with only type + string) · Issue #134582 · python/cpython · GitHub

Repository navigation

untokenize() round-trip fails for t-strings (with only type + string) #134582

Closed

Description

Bug report

Bug description:

Found when investigating test.test_tokenize.TestRoundtrip.test_random_files failing on #134577

def test(code):
    tokens = list(tokenize.tokenize(iter([code]).__next__))
    from5 = tokenize.untokenize(tokens)
    print("from5   ", from5, eval(from5))

    tokens2 = [tok[:2] for tok in tokens]
    from2 = tokenize.untokenize(tokens2)
    print("from2   ", from2, eval(from2))
>>> test(b't"{ {} }"')
from5    b't"{ {} }"' Template(strings=('', ''), interpolations=(Interpolation({}, ' {}', None, ''),))
from2    b't"{{}}"'   Template(strings=('{}',), interpolations=())

>>> test(b'f"{ {} }"')
from5    b'f"{ {} }"' {}
from2    b'f"{ {} }"' {}

From what I understand, untokenize should round-trip correctly even with only the type and string of tokens.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.14bugs and security fixes
    3.15bugs and security fixes
    on May 23, 2025
  2. added a commit that references this issue on May 25, 2025
  3. added a commit that references this issue on May 25, 2025
  4. added a commit that references this issue on May 25, 2025
  5. added a commit that references this issue on Jul 12, 2025
  6. added a commit that references this issue on Aug 4, 2025
  7. added a commit that references this issue on Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15bugs and security fixesinterpreter-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


      Back | FazBrowse Home | New Git URL