diff --git a/crates/ruff/resources/test/fixtures/flake8_type_checking/TCH002.py b/crates/ruff/resources/test/fixtures/flake8_type_checking/TCH002.py index 0f72877a75..2bda6ff983 100644 --- a/crates/ruff/resources/test/fixtures/flake8_type_checking/TCH002.py +++ b/crates/ruff/resources/test/fixtures/flake8_type_checking/TCH002.py @@ -44,7 +44,7 @@ def f(): def f(): - import pandas as pd + import pandas as pd # TCH002 x = dict["pd.DataFrame", "pd.DataFrame"] diff --git a/crates/ruff/src/checkers/ast.rs b/crates/ruff/src/checkers/ast.rs index 65d35524ef..31283f5d3c 100644 --- a/crates/ruff/src/checkers/ast.rs +++ b/crates/ruff/src/checkers/ast.rs @@ -3900,7 +3900,10 @@ impl<'a> Checker<'a> { } pub const fn execution_context(&self) -> ExecutionContext { - if self.in_type_checking_block || self.in_annotation { + if self.in_type_checking_block + || self.in_annotation + || self.in_deferred_string_type_definition + { ExecutionContext::Typing } else { ExecutionContext::Runtime diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_8.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_8.py.snap index 7a8ec40dff..b308635bbd 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_8.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_8.py.snap @@ -2,15 +2,5 @@ source: crates/ruff/src/rules/flake8_type_checking/mod.rs expression: diagnostics --- -- kind: - RuntimeImportInTypeCheckingBlock: - full_name: typing.Any - location: - row: 5 - column: 23 - end_location: - row: 5 - column: 26 - fix: ~ - parent: ~ +[] diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_TCH002.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_TCH002.py.snap index 180c62996e..c62ba0be8d 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_TCH002.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_TCH002.py.snap @@ -79,4 +79,15 @@ expression: diagnostics column: 23 fix: ~ parent: ~ +- kind: + TypingOnlyThirdPartyImport: + full_name: pandas + location: + row: 47 + column: 11 + end_location: + row: 47 + column: 23 + fix: ~ + parent: ~