[ty] Don't warn yield not in function when yield is in function (#18008)

This commit is contained in:
Max Mynter 2025-05-21 18:16:25 +02:00 committed by GitHub
parent d37592175f
commit 02fd48132c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 87 additions and 17 deletions

View file

@ -2481,6 +2481,18 @@ impl SemanticSyntaxContext for SemanticIndexBuilder<'_> {
false
}
fn in_yield_allowed_context(&self) -> bool {
for scope_info in self.scope_stack.iter().rev() {
let scope = &self.scopes[scope_info.file_scope_id];
match scope.kind() {
ScopeKind::Class | ScopeKind::Comprehension => return false,
ScopeKind::Function | ScopeKind::Lambda => return true,
ScopeKind::Module | ScopeKind::TypeAlias | ScopeKind::Annotation => {}
}
}
false
}
fn in_sync_comprehension(&self) -> bool {
for scope_info in self.scope_stack.iter().rev() {
let scope = &self.scopes[scope_info.file_scope_id];