diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 4d4d7e9293..fb163f8006 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -437,6 +437,11 @@ impl<'a> Checker<'a> { } } + /// Returns the [`Tokens`] for the parsed source file + pub(crate) fn source_tokens(&self) -> &'a Tokens { + self.parsed.tokens() + } + /// The [`Locator`] for the current file, which enables extraction of source code from byte /// offsets. pub(crate) const fn locator(&self) -> &'a Locator<'a> { diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs index 11cd3e9e83..c07de4b813 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/type_alias_quotes.rs @@ -301,7 +301,7 @@ pub(crate) fn quoted_type_alias( // Check for parentheses outside the string ("""...""") annotation_expr.into(), checker.semantic().current_statement().into(), - checker.tokens(), + checker.source_tokens(), ) .is_none() && parenthesized_range( diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__quoted-type-alias_TC008.py.snap b/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__quoted-type-alias_TC008.py.snap index c4b428973b..53f8bb88a0 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__quoted-type-alias_TC008.py.snap +++ b/crates/ruff_linter/src/rules/flake8_type_checking/snapshots/ruff_linter__rules__flake8_type_checking__tests__quoted-type-alias_TC008.py.snap @@ -470,8 +470,8 @@ help: Remove quotes 60 | # P, Q, and R should not have parenthesis added - p: TypeAlias = ("""int - | None""") -61 + p: TypeAlias = ((int -62 + | None)) +61 + p: TypeAlias = (int +62 + | None) 63 | type P = ("""int 64 | | None""") 65 | @@ -494,8 +494,8 @@ help: Remove quotes 62 | | None""") - type P = ("""int - | None""") -63 + type P = ((int -64 + | None)) +63 + type P = (int +64 + | None) 65 | 66 | q: TypeAlias = """(int 67 | | None)"""