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

Method compile_annotation

crates/codegen/src/compile.rs:7071–7098  ·  view source on GitHub ↗
(&mut self, annotation: &ast::Expr)

Source from the content-addressed store, hash-verified

7069 }
7070
7071 fn compile_annotation(&mut self, annotation: &ast::Expr) -> CompileResult<()> {
7072 if self.future_annotations {
7073 self.emit_load_const(ConstantData::Str {
7074 value: UnparseExpr::new(annotation, &self.source_file)
7075 .to_string()
7076 .into(),
7077 });
7078 } else {
7079 let was_in_annotation = self.in_annotation;
7080 self.in_annotation = true;
7081
7082 // Special handling for starred annotations (*Ts -> Unpack[Ts])
7083 let result = match annotation {
7084 ast::Expr::Starred(ast::ExprStarred { value, .. }) => {
7085 // *args: *Ts (where Ts is a TypeVarTuple).
7086 // Do [annotation_value] = [*Ts].
7087 self.compile_expression(value)?;
7088 emit!(self, Instruction::UnpackSequence { count: 1 });
7089 Ok(())
7090 }
7091 _ => self.compile_expression(annotation),
7092 };
7093
7094 self.in_annotation = was_in_annotation;
7095 result?;
7096 }
7097 Ok(())
7098 }
7099
7100 fn compile_annotated_assign(
7101 &mut self,

Callers 3

Calls 4

newFunction · 0.85
emit_load_constMethod · 0.80
to_stringMethod · 0.80
compile_expressionMethod · 0.80

Tested by

no test coverage detected