Skip to content

Commit

Permalink
Ignore Q000, Q001 when string is inside forward ref
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Mar 25, 2024
1 parent 21f63c5 commit 3638dac
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 3638dac

Please sign in to comment.