MCPcopy Index your code
hub / github.com/RustPython/RustPython / is_in_async_context

Method is_in_async_context

crates/codegen/src/symboltable.rs:1173–1193  ·  view source on GitHub ↗

Walk up the scope chain to determine if we're inside an async function. Annotation and TypeParams scopes act as async barriers (always non-async). Comprehension scopes are transparent (inherit parent's async context).

(&self)

Source from the content-addressed store, hash-verified

1171 /// Annotation and TypeParams scopes act as async barriers (always non-async).
1172 /// Comprehension scopes are transparent (inherit parent's async context).
1173 fn is_in_async_context(&self) -> bool {
1174 // Annotations are evaluated in a non-async scope even when
1175 // the enclosing function is async.
1176 if self.in_annotation {
1177 return false;
1178 }
1179 for table in self.tables.iter().rev() {
1180 match table.typ {
1181 CompilerScope::AsyncFunction => return true,
1182 CompilerScope::Function
1183 | CompilerScope::Lambda
1184 | CompilerScope::Class
1185 | CompilerScope::Module
1186 | CompilerScope::Annotation
1187 | CompilerScope::TypeParams => return false,
1188 // Comprehension inherits parent's async context
1189 CompilerScope::Comprehension => continue,
1190 }
1191 }
1192 false
1193 }
1194
1195 fn line_index_start(&self, range: TextRange) -> u32 {
1196 self.source_file

Callers 1

scan_comprehensionMethod · 0.80

Calls 2

revMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected