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

Method enter_annotation_scope

crates/codegen/src/compile.rs:1373–1411  ·  view source on GitHub ↗

Enter annotation scope using the symbol table's annotation_block. Returns None if no annotation_block exists. On success, returns the saved CompileContext to pass to exit_annotation_scope.

(
        &mut self,
        _func_name: &str,
    )

Source from the content-addressed store, hash-verified

1371 /// Returns None if no annotation_block exists.
1372 /// On success, returns the saved CompileContext to pass to exit_annotation_scope.
1373 fn enter_annotation_scope(
1374 &mut self,
1375 _func_name: &str,
1376 ) -> CompileResult<Option<CompileContext>> {
1377 if !self.push_annotation_symbol_table() {
1378 return Ok(None);
1379 }
1380
1381 // Annotation scopes are never async (even inside async functions)
1382 let saved_ctx = self.ctx;
1383 self.ctx = CompileContext {
1384 loop_data: None,
1385 in_class: saved_ctx.in_class,
1386 func: FunctionContext::Function,
1387 in_async_scope: false,
1388 };
1389
1390 let key = self.symbol_table_stack.len() - 1;
1391 let lineno = self.get_source_line_number().get();
1392 self.enter_scope(
1393 "__annotate__",
1394 CompilerScope::Annotation,
1395 key,
1396 lineno.to_u32(),
1397 )?;
1398
1399 // Override arg_count since enter_scope sets it to 1 but we need the varnames
1400 // setup to be correct too
1401 self.current_code_info()
1402 .metadata
1403 .varnames
1404 .insert("format".to_owned());
1405
1406 // Emit format validation: if format > VALUE_WITH_FAKE_GLOBALS: raise NotImplementedError
1407 // VALUE_WITH_FAKE_GLOBALS = 2 (from annotationlib.Format)
1408 self.emit_format_validation()?;
1409
1410 Ok(Some(saved_ctx))
1411 }
1412
1413 /// Emit format parameter validation for annotation scope
1414 /// if format > VALUE_WITH_FAKE_GLOBALS (2): raise NotImplementedError

Callers 1

Calls 11

current_code_infoMethod · 0.80
SomeClass · 0.50
lenMethod · 0.45
getMethod · 0.45
enter_scopeMethod · 0.45
to_u32Method · 0.45
insertMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected