Repository navigation
Commit 8a80b12
Fix patchedast region for implicitly-concatenated f-strings
`_JoinedStr` builds its children as [start_quote, *FormattedValues,
end_quote] and lets `_handle` consume each by forward search. The
end-quote child therefore matches the first closing quote after the last
interpolation -- which, in an implicit concatenation, closes only the
part that held that interpolation, not the whole concatenation.
The node's region was then understated and, worse, the scanner was left
parked inside source text that had not been recognised as a string
literal. A `#` in a trailing part -- `f"{a} one " f"#52 two"` -- then
reads to `_good_token` as the start of a real comment, so the following
`)` is skipped as commented-out and `consume` raises
MismatchedTokenError (issue #879).
The truncation itself predates the `#`: a hash-free concatenation such
as `f"{a} one " f"52 two"` also produced a short region, it just failed
silently because nothing downstream needed to match a token past the
truncation point.
`consume_string` already measures the full concatenation before
`_JoinedStr` rewinds the scanner, so close the gap from its end offset
rather than re-scanning. Plain (non-f) strings were never affected
because `_Str` consumes via that same pattern.
Fixes #879
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent e1f2cc2 commit 8a80b12
3 files changed
Lines changed: 70 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
411 | 432 | | |
412 | 433 | | |
413 | 434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
340 | 382 | | |
341 | 383 | | |
342 | 384 | | |
| |||
2001 | 2043 | | |
2002 | 2044 | | |
2003 | 2045 | | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
2004 | 2052 | | |
2005 | 2053 | | |
2006 | 2054 | | |
| |||
0 commit comments