Skip to content

Commit 72332c9

Browse files
authored
Merge pull request RustPython#4226 from jopemachine/fix-class-static
Fix lambda expression's unexpected `UnboundLocalError`
2 parents 6d140fb + 117ae0a commit 72332c9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/codegen/src/compile.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,15 +2118,16 @@ impl Compiler {
21182118
Name { id, .. } => self.load_name(id)?,
21192119
Lambda { args, body } => {
21202120
let prev_ctx = self.ctx;
2121+
2122+
let name = "<lambda>".to_owned();
2123+
let mut funcflags = self.enter_function(&name, args)?;
2124+
21212125
self.ctx = CompileContext {
21222126
loop_data: Option::None,
21232127
in_class: prev_ctx.in_class,
21242128
func: FunctionContext::Function,
21252129
};
21262130

2127-
let name = "<lambda>".to_owned();
2128-
let mut funcflags = self.enter_function(&name, args)?;
2129-
21302131
self.current_codeinfo()
21312132
.constants
21322133
.insert_full(ConstantData::None);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class X:
2+
v = 10
3+
f = lambda x=v: x

0 commit comments

Comments
 (0)