Ignore brackets inside f-string text in check_complete 馃馃 - #15407
Open
MohammadHijjawi97 wants to merge 1 commit into
Open
MohammadHijjawi97 wants to merge 1 commit into
MohammadHijjawi97 wants to merge 1 commit into
Conversation
Since Python 3.12, f-strings are tokenized into FSTRING_START /
FSTRING_MIDDLE / FSTRING_END, so a literal "[" or "]" in the text part
of an f-string shows up as a token whose string is a bracket.
make_tokens_by_line and has_sunken_brackets counted those as real
brackets, which made check_complete:
- report 'complete' for an indented block whose last line is a comment
following e.g. `x = f"[{i}] "`, so the block ran early (ipython#14481);
- report 'invalid' for valid code like `x = f"]"`.
Only count OP tokens as brackets.
Fixes ipython#14481
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14481 馃馃
Since Python 3.12, f-strings are tokenized as FSTRING_START / FSTRING_MIDDLE / FSTRING_END. A literal
[or]in the text part of an f-string therefore becomes a token whose.stringis a bracket.make_tokens_by_lineandhas_sunken_bracketscounted those as real brackets, socheck_complete:completefor an indented block ending in a comment after e.g.x = f"[{i}] ", so the loop ran as soon as the comment line was entered (the report in Comment line executes loop if the previous line is an f-string?聽#14481);invalidfor valid code such asx = f"]".Only
OPtokens are now counted as brackets. Regression cases added totest_check_complete_param.