Short-circuit typing matches based on imports (#9800)

This commit is contained in:
Charlie Marsh 2024-02-04 11:06:44 -08:00 committed by GitHub
parent c53aae0b6f
commit 5c99967c4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 128 additions and 48 deletions

View file

@ -161,6 +161,11 @@ pub fn to_pep604_operator(
}
}
// If the typing modules were never imported, we'll never match below.
if !semantic.seen_typing() {
return None;
}
// If the slice is a forward reference (e.g., `Optional["Foo"]`), it can only be rewritten
// if we're in a typing-only context.
//