Skip setattr(__doc__) if not given

This commit is contained in:
Jeong YunWon
2024-04-23 21:58:36 +09:00
committed by Jeong, YunWon
parent ada10067dd
commit 075c69a3cd

View File

@@ -1266,11 +1266,13 @@ impl Compiler {
// Turn code object into function object:
emit!(self, Instruction::MakeFunction(func_flags));
emit!(self, Instruction::Duplicate);
self.load_docstring(doc_str);
emit!(self, Instruction::Rotate2);
let doc = self.name("__doc__");
emit!(self, Instruction::StoreAttr { idx: doc });
if let Some(value) = doc_str {
emit!(self, Instruction::Duplicate);
self.emit_constant(ConstantData::Str { value });
emit!(self, Instruction::Rotate2);
let doc = self.name("__doc__");
emit!(self, Instruction::StoreAttr { idx: doc });
}
self.apply_decorators(decorator_list);