-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update RUF001
, RUF003
to check in f-strings
#7477
Merged
+131
−16
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ confusables.py:31:6: RUF001 String contains ambiguous `Р` (CYRILLIC CAPITAL LET | |
30 | # boundary" (whitespace) that it itself ambiguous. | ||
31 | x = "Р усский" | ||
| ^ RUF001 | ||
32 | | ||
33 | # Same test cases as above but using f-strings instead: | ||
| | ||
|
||
confusables.py:31:7: RUF001 String contains ambiguous ` ` (EN QUAD). Did you mean ` ` (SPACE)? | ||
|
@@ -57,6 +59,100 @@ confusables.py:31:7: RUF001 String contains ambiguous ` ` (EN QUAD). Did you m | |
30 | # boundary" (whitespace) that it itself ambiguous. | ||
31 | x = "Р усский" | ||
| ^ RUF001 | ||
32 | | ||
33 | # Same test cases as above but using f-strings instead: | ||
| | ||
|
||
confusables.py:34:7: RUF001 String contains ambiguous `𝐁` (MATHEMATICAL BOLD CAPITAL B). Did you mean `B` (LATIN CAPITAL LETTER B)? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a new context to make this message say "F-string contains ..." instead of "String contains ..."? |
||
| | ||
33 | # Same test cases as above but using f-strings instead: | ||
34 | x = f"𝐁ad string" | ||
| ^ RUF001 | ||
35 | x = f"−" | ||
36 | x = f"Русский" | ||
| | ||
|
||
confusables.py:37:11: RUF001 String contains ambiguous `α` (GREEK SMALL LETTER ALPHA). Did you mean `a` (LATIN SMALL LETTER A)? | ||
| | ||
35 | x = f"−" | ||
36 | x = f"Русский" | ||
37 | x = f"βα Bαd" | ||
| ^ RUF001 | ||
38 | x = f"Р усский" | ||
| | ||
|
||
confusables.py:38:7: RUF001 String contains ambiguous `Р` (CYRILLIC CAPITAL LETTER ER). Did you mean `P` (LATIN CAPITAL LETTER P)? | ||
| | ||
36 | x = f"Русский" | ||
37 | x = f"βα Bαd" | ||
38 | x = f"Р усский" | ||
| ^ RUF001 | ||
39 | | ||
40 | # Nested f-strings | ||
| | ||
|
||
confusables.py:38:8: RUF001 String contains ambiguous ` ` (EN QUAD). Did you mean ` ` (SPACE)? | ||
| | ||
36 | x = f"Русский" | ||
37 | x = f"βα Bαd" | ||
38 | x = f"Р усский" | ||
| ^ RUF001 | ||
39 | | ||
40 | # Nested f-strings | ||
| | ||
|
||
confusables.py:41:7: RUF001 String contains ambiguous `𝐁` (MATHEMATICAL BOLD CAPITAL B). Did you mean `B` (LATIN CAPITAL LETTER B)? | ||
| | ||
40 | # Nested f-strings | ||
41 | x = f"𝐁ad string {f" {f"Р усский"}"}" | ||
| ^ RUF001 | ||
42 | | ||
43 | # Comments inside f-strings | ||
| | ||
|
||
confusables.py:41:21: RUF001 String contains ambiguous ` ` (EN QUAD). Did you mean ` ` (SPACE)? | ||
| | ||
40 | # Nested f-strings | ||
41 | x = f"𝐁ad string {f" {f"Р усский"}"}" | ||
| ^ RUF001 | ||
42 | | ||
43 | # Comments inside f-strings | ||
| | ||
|
||
confusables.py:41:25: RUF001 String contains ambiguous `Р` (CYRILLIC CAPITAL LETTER ER). Did you mean `P` (LATIN CAPITAL LETTER P)? | ||
| | ||
40 | # Nested f-strings | ||
41 | x = f"𝐁ad string {f" {f"Р усский"}"}" | ||
| ^ RUF001 | ||
42 | | ||
43 | # Comments inside f-strings | ||
| | ||
|
||
confusables.py:41:26: RUF001 String contains ambiguous ` ` (EN QUAD). Did you mean ` ` (SPACE)? | ||
| | ||
40 | # Nested f-strings | ||
41 | x = f"𝐁ad string {f" {f"Р усский"}"}" | ||
| ^ RUF001 | ||
42 | | ||
43 | # Comments inside f-strings | ||
| | ||
|
||
confusables.py:44:68: RUF003 Comment contains ambiguous `)` (FULLWIDTH RIGHT PARENTHESIS). Did you mean `)` (RIGHT PARENTHESIS)? | ||
| | ||
43 | # Comments inside f-strings | ||
44 | x = f"string { # And here's a comment with an unusual parenthesis: ) | ||
| ^^ RUF003 | ||
45 | # And here's a comment with a greek alpha: ∗ | ||
46 | foo # And here's a comment with an unusual punctuation mark: ᜵ | ||
| | ||
|
||
confusables.py:46:62: RUF003 Comment contains ambiguous `᜵` (PHILIPPINE SINGLE PUNCTUATION). Did you mean `/` (SOLIDUS)? | ||
| | ||
44 | x = f"string { # And here's a comment with an unusual parenthesis: ) | ||
45 | # And here's a comment with a greek alpha: ∗ | ||
46 | foo # And here's a comment with an unusual punctuation mark: ᜵ | ||
| ^ RUF003 | ||
47 | }" | ||
| | ||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this "state machine" need any updating to correctly handle fstrings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as f-strings cannot be used as docstrings. The state machine is mainly used for docstring detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. But does it need any updating to not get confused by the new tokens emitted by the lexer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. No, it doesn't. The reason being that the detection mechanism resets the state if it finds any token other than the string token after a function / class / module.