Skip to content

Comments

Fix f-string middle panic when parsing t-strings#23232

Merged
ntBre merged 6 commits intomainfrom
brent/f-string-middle
Feb 12, 2026
Merged

Fix f-string middle panic when parsing t-strings#23232
ntBre merged 6 commits intomainfrom
brent/f-string-middle

Conversation

@ntBre
Copy link
Contributor

@ntBre ntBre commented Feb 11, 2026

Summary

This PR fixes #23198 by copying Dylan's changes from #19183 to the other
InterpolatedStringElementsKind variant, in line with Micha's prophetic comment (https://github.com/astral-sh/ruff/pull/19183/changes#r2217325217).

Test Plan

Two new tests derived from the issue

@ntBre ntBre added bug Something isn't working parser Related to the parser labels Feb 11, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 11, 2026

Merging this PR will not alter performance

✅ 54 untouched benchmarks


Comparing brent/f-string-middle (dbe80c2) with main (647f660)

Open in CodSpeed

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 11, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Summary
--

This PR fixes #23198 by copying Dylan's changes from #19183 to the other
`InterpolatedStringElementsKind` variant, in line with Micha's prophetic comment (https://github.com/astral-sh/ruff/pull/19183/changes#r2217325217).

Test Plan
--

Two new tests derived from the issue
@ntBre ntBre force-pushed the brent/f-string-middle branch from ef64124 to ba00d52 Compare February 11, 2026 18:04
@ntBre
Copy link
Contributor Author

ntBre commented Feb 11, 2026

Not really sure what happened with the benchmarks, but it cleared up after rebasing on main. There are some ~2% regressions but also some improvements, so I think it's pretty neutral overall, as I would expect.

@ntBre ntBre marked this pull request as ready for review February 11, 2026 18:27
@ntBre ntBre requested a review from dylwil3 February 11, 2026 18:27
@dylwil3
Copy link
Collaborator

dylwil3 commented Feb 11, 2026

in line with Micha's prophetic comment

truly a red flag that I casually asserted Micha was wrong. we should add a CI check for that.

Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me! I'm glad it wasn't too painful.

Comment on lines 1343 to 1344
const F_STRING_ELEMENTS_IN_FORMAT_SPEC = 1 << 27;
const T_STRING_ELEMENTS_IN_FORMAT_SPEC = 1 << 31;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird that we skipped 27 (did I do that??)
should we just renumber them sequentially or does that break something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was weird, but it wasn't you! It was like that before your PR. I'm assuming one of them got removed at some point?

I vaguely remember trying to reorder a different set of bitflags previously and someone suggested leaving them alone, but I'm happy to do it if you prefer. Maybe @dhruvmanila will have an opinion too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to change the values, I'm assuming that we should avoid doing that mainly to make the reviewing easier but I guess you could do it before merging. Anyways, this doesn't look like a big change 🤷‍♂️

@ntBre
Copy link
Contributor Author

ntBre commented Feb 11, 2026

It wasn't painful at all! You had already done the hard work for me 😄

@ntBre ntBre enabled auto-merge (squash) February 12, 2026 14:24
@ntBre ntBre merged commit 6ded4be into main Feb 12, 2026
41 checks passed
@ntBre ntBre deleted the brent/f-string-middle branch February 12, 2026 14:27
@samuelcolvin
Copy link

Thanks so much for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parser Related to the parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic: entered unreachable code: t-string: unexpected token FStringMiddle

4 participants