From 075c69a3cdbeb51a85aeee3a861e40efe505d71f Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Tue, 23 Apr 2024 21:58:36 +0900 Subject: [PATCH] Skip setattr(__doc__) if not given --- compiler/codegen/src/compile.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index bf0fbe1dec..ec26515dfb 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -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);