Skip to content

Commit

Permalink
Ignore Q000, Q001 when string is inside forward ref (#10585)
Browse files Browse the repository at this point in the history
## Summary

This is not the holistic solution but just to fix that issue.

fixes: #10546 

## Test Plan

Add a regression test for it and check the snapshots.
  • Loading branch information
dhruvmanila authored Mar 25, 2024
1 parent 3e1f3b8 commit 4950ca4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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

0 comments on commit 4950ca4

Please sign in to comment.