Skip to content
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

Ignore Q000, Q001 when string is inside forward ref #10585

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
this_should_be_linted = u'double quote string'
this_should_be_linted = f'double quote string'
this_should_be_linted = f'double {"quote"} string'

# https://github.com/astral-sh/ruff/issues/10546
x: "Literal['foo', 'bar']"
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ fn strings(checker: &mut Checker, sequence: &[TextRange]) {

/// Generate `flake8-quote` diagnostics from a token stream.
pub(crate) fn check_string_quotes(checker: &mut Checker, string_like: StringLike) {
// Ignore if the string is part of a forward reference. For example,
// `x: "Literal['foo', 'bar']"`.
if checker.semantic().in_string_type_definition() {
return;
}

// If the string is part of a f-string, ignore it.
if checker
.indexer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ singles.py:2:25: Q000 [*] Single quotes found but double quotes preferred
2 |+this_should_be_linted = u"double quote string"
3 3 | this_should_be_linted = f'double quote string'
4 4 | this_should_be_linted = f'double {"quote"} string'
5 5 |

singles.py:3:25: Q000 [*] Single quotes found but double quotes preferred
|
Expand All @@ -50,5 +51,5 @@ singles.py:3:25: Q000 [*] Single quotes found but double quotes preferred
3 |-this_should_be_linted = f'double quote string'
3 |+this_should_be_linted = f"double quote string"
4 4 | this_should_be_linted = f'double {"quote"} string'


5 5 |
6 6 | # https://github.com/astral-sh/ruff/issues/10546
Loading