Only overwrite the locals in __build_class__ if it's a class

This commit is contained in:
Noah 2019-09-10 11:37:11 -05:00 committed by coolreader18
parent a29fb0de12
commit fee1b6f2c7
2 changed files with 13 additions and 2 deletions

View file

@ -955,12 +955,21 @@ impl<O: OutputStream> Compiler<O> {
self.emit(Instruction::LoadName {
name: "__name__".to_string(),
scope: bytecode::NameScope::Free,
scope: bytecode::NameScope::Global,
});
self.emit(Instruction::StoreName {
name: "__module__".to_string(),
scope: bytecode::NameScope::Free,
});
self.emit(Instruction::LoadConst {
value: bytecode::Constant::String {
value: qualified_name.clone(),
},
});
self.emit(Instruction::StoreName {
name: "__qualname__".to_string(),
scope: bytecode::NameScope::Free,
});
self.compile_statements(new_body)?;
self.emit(Instruction::LoadConst {
value: bytecode::Constant::None,
@ -983,7 +992,7 @@ impl<O: OutputStream> Compiler<O> {
// Turn code object into function object:
self.emit(Instruction::MakeFunction {
flags: bytecode::FunctionOpArg::empty(),
flags: bytecode::FunctionOpArg::NO_NEW_LOCALS,
});
self.emit(Instruction::LoadConst {