diff --git a/compiler/codegen/src/symboltable.rs b/compiler/codegen/src/symboltable.rs index f215ce38f4..66dbff326a 100644 --- a/compiler/codegen/src/symboltable.rs +++ b/compiler/codegen/src/symboltable.rs @@ -80,6 +80,7 @@ pub enum SymbolTableType { Module, Class, Function, + Lambda, Comprehension, TypeParams, } @@ -90,6 +91,7 @@ impl fmt::Display for SymbolTableType { Self::Module => write!(f, "module"), Self::Class => write!(f, "class"), Self::Function => write!(f, "function"), + Self::Lambda => write!(f, "lambda"), Self::Comprehension => write!(f, "comprehension"), Self::TypeParams => write!(f, "type parameter"), // TODO missing types from the C implementation @@ -493,7 +495,7 @@ impl SymbolTableAnalyzer { location: None, }); } - SymbolTableType::Function => { + SymbolTableType::Function | SymbolTableType::Lambda => { if let Some(parent_symbol) = symbols.get_mut(&symbol.name) { if let SymbolScope::Unknown = parent_symbol.scope { // this information is new, as the assignment is done in inner scope @@ -1140,7 +1142,7 @@ impl SymbolTableBuilder<'_> { } else { self.enter_scope( "lambda", - SymbolTableType::Function, + SymbolTableType::Lambda, self.line_index_start(expression.range()), ); } diff --git a/compiler/core/src/bytecode.rs b/compiler/core/src/bytecode.rs index 3fe9356004..a27174e859 100644 --- a/compiler/core/src/bytecode.rs +++ b/compiler/core/src/bytecode.rs @@ -414,7 +414,7 @@ op_arg_enum!( // PrepReraiseS tar = 1, // TypeVarWithBound = 2, // TypeVarWithConstraints = 3, - // SetFunctionTypeParams = 4, + SetFunctionTypeParams = 4, /// Set default value for type parameter (PEP 695) SetTypeparamDefault = 5, } diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 2bcfeebf54..6c9181c2c1 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -2286,6 +2286,12 @@ impl ExecutingFrame<'_> { bytecode::IntrinsicFunction2::SetTypeparamDefault => { crate::stdlib::typing::set_typeparam_default(arg1, arg2, vm) } + bytecode::IntrinsicFunction2::SetFunctionTypeParams => { + // arg1 is the function, arg2 is the type params tuple + // Set __type_params__ attribute on the function + arg1.set_attr("__type_params__", arg2, vm)?; + Ok(arg1) + } } }