Skip to content

Avoid moving back the lexer for triple-quoted fstring#11939

Merged
dhruvmanila merged 1 commit intomainfrom
dhruv/re-lexing-fstring-bug
Jun 20, 2024
Merged

Avoid moving back the lexer for triple-quoted fstring#11939
dhruvmanila merged 1 commit intomainfrom
dhruv/re-lexing-fstring-bug

Conversation

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Jun 19, 2024

Summary

This PR avoids moving back the lexer for a triple-quoted f-string during the re-lexing phase.

The reason this is a problem is that for a triple-quoted f-string the newlines are part of the f-string itself, specifically they'll be part of the FStringMiddle token. So, if we moved the lexer back, there would be a Newline token whose range would be in between an FStringMiddle token. This creates a panic in downstream usage.

fixes: #11937

Test Plan

Add test cases and validate the snapshots.

@dhruvmanila dhruvmanila added bug Something isn't working parser Related to the parser labels Jun 19, 2024
@github-actions
Copy link
Contributor

github-actions bot commented Jun 19, 2024

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.

@dhruvmanila dhruvmanila force-pushed the dhruv/re-lexing-fstring-bug branch from 8f1ccc9 to 9ba57f4 Compare June 19, 2024 12:42
@dhruvmanila dhruvmanila marked this pull request as ready for review June 20, 2024 09:00
@dhruvmanila dhruvmanila requested a review from MichaReiser as a code owner June 20, 2024 09:00
@dhruvmanila dhruvmanila merged commit ed948ea into main Jun 20, 2024
@dhruvmanila dhruvmanila deleted the dhruv/re-lexing-fstring-bug branch June 20, 2024 10:57
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.

Rule PYI010 cause panic

2 participants