[ruff] Skip RUF001 diagnostics when visiting string type definitions (#16122)

This commit is contained in:
Alex Waygood 2025-02-12 16:27:38 +00:00 committed by GitHub
parent a9671e7008
commit c31352f52b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 1 deletions

View file

@ -56,3 +56,6 @@ assert getattr(Labware(), "µL") == 1.5
# Implicit string concatenation
x = "𝐁ad" f"𝐁ad string"
from typing import Literal
x: '''"""'Literal[""]'"""'''

View file

@ -186,7 +186,13 @@ pub(crate) fn ambiguous_unicode_character_comment(
/// RUF001, RUF002
pub(crate) fn ambiguous_unicode_character_string(checker: &Checker, string_like: StringLike) {
let context = if checker.semantic().in_pep_257_docstring() {
let semantic = checker.semantic();
if semantic.in_string_type_definition() {
return;
}
let context = if semantic.in_pep_257_docstring() {
Context::Docstring
} else {
Context::String

View file

@ -160,6 +160,8 @@ confusables.py:58:6: RUF001 String contains ambiguous `𝐁` (MATHEMATICAL BOLD
57 | # Implicit string concatenation
58 | x = "𝐁ad" f"𝐁ad string"
| ^ RUF001
59 |
60 | from typing import Literal
|
confusables.py:58:13: RUF001 String contains ambiguous `𝐁` (MATHEMATICAL BOLD CAPITAL B). Did you mean `B` (LATIN CAPITAL LETTER B)?
@ -167,4 +169,13 @@ confusables.py:58:13: RUF001 String contains ambiguous `𝐁` (MATHEMATICAL BOLD
57 | # Implicit string concatenation
58 | x = "𝐁ad" f"𝐁ad string"
| ^ RUF001
59 |
60 | from typing import Literal
|
confusables.py:61:20: RUF001 String contains ambiguous `` (ARABIC LETTER HEH GOAL INITIAL FORM). Did you mean `o` (LATIN SMALL LETTER O)?
|
60 | from typing import Literal
61 | x: '''"""'Literal[""]'"""'''
| ^ RUF001
|

View file

@ -168,6 +168,8 @@ confusables.py:58:6: RUF001 String contains ambiguous `𝐁` (MATHEMATICAL BOLD
57 | # Implicit string concatenation
58 | x = "𝐁ad" f"𝐁ad string"
| ^ RUF001
59 |
60 | from typing import Literal
|
confusables.py:58:13: RUF001 String contains ambiguous `𝐁` (MATHEMATICAL BOLD CAPITAL B). Did you mean `B` (LATIN CAPITAL LETTER B)?
@ -175,4 +177,13 @@ confusables.py:58:13: RUF001 String contains ambiguous `𝐁` (MATHEMATICAL BOLD
57 | # Implicit string concatenation
58 | x = "𝐁ad" f"𝐁ad string"
| ^ RUF001
59 |
60 | from typing import Literal
|
confusables.py:61:20: RUF001 String contains ambiguous `` (ARABIC LETTER HEH GOAL INITIAL FORM). Did you mean `o` (LATIN SMALL LETTER O)?
|
60 | from typing import Literal
61 | x: '''"""'Literal[""]'"""'''
| ^ RUF001
|