Avoid treating deferred string annotations as required-at-runtime (#2779)

This commit is contained in:
Charlie Marsh 2023-02-11 15:00:08 -05:00 committed by GitHub
parent 74731a3456
commit 5a70a573cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 13 deletions

View file

@ -44,7 +44,7 @@ def f():
def f():
import pandas as pd
import pandas as pd # TCH002
x = dict["pd.DataFrame", "pd.DataFrame"]

View file

@ -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

View file

@ -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: ~
[]

View file

@ -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: ~