Skip to content

Canonicalize nested template format specs in annotations - #9076

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-tstring-format-spec-unparse
Oct 11, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-tstring-format-spec-unparse

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Extract the independent template format-spec unparse correction from #8954. Interpolation format specs contain ordinary formatted-value fields and must use the existing f-string body unparser. The outer template interpolation continues to preserve its source spelling.

For example, a future annotation containing t'{value:{(width)}}' is canonically stored as t'{value:{width}}'. This one-line dispatch fix matches CPython 3.14.7 and 3.14.8.

No broader interpolation text, debug-comment, or newline reconstruction changes are included. Checked adjacent #8160 and other open codegen work; this is the separate format-spec dispatch.

Validation

  • Independent source review and exact-diff review.
  • Existing Python annotation snippet gains three compile-only cases: literal format spec, nested redundant parentheses, and preserved outer spelling with nested conversion.
  • Full snippet passes on CPython 3.14.7 and 3.14.8; the prior native binary fails the new assertion. Patched native snippet and both selected pytest cases pass.
  • Unchanged canonical test_unparse.UnparseTestCase.test_tstrings and existing structural future-template annotation test pass.
  • Normal hooks, native build, codegen/VM and separately configured C-API Clippy with warnings denied.

The regression only compiles and inspects annotation constants; it never executes the generated annotation or formatting callbacks. Local validation is Linux; the full hosted matrix remains required.

Use the existing f-string body unparser for template interpolation format specs, while preserving the outer interpolation source text. Add compile-only Python annotation-constant coverage.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b478208c-8992-4e9f-baec-b5735cd8ee1f

📥 Commits

Reviewing files that changed from the base of the PR and between 9d6bf4d and 54f099a.


📒 Files selected for processing (2)
  • crates/codegen/src/unparse.rs
  • extra_tests/snippets/syntax_annotations.py

 ____________________________________________________________________________________________________________________________________________
< Organize teams around functionality. Don't separate designers from coders, testers from data modelers. Build teams the way you build code. >
 --------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed

codspeed Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix-tstring-format-spec-unparse (54f099a) with main (9d6bf4d)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone marked this pull request as ready for review October 11, 2026 00:16
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@youknowone
youknowone merged commit 8d27253 into RustPython:main Oct 11, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants