Skip to content

Commit 075c69a

Browse files
committed
Skip setattr(__doc__) if not given
1 parent ada1006 commit 075c69a

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎compiler/codegen/src/compile.rs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,11 +1266,13 @@ impl Compiler {
12661266
// Turn code object into function object:
12671267
emit!(self, Instruction::MakeFunction(func_flags));
12681268

1269-
emit!(self, Instruction::Duplicate);
1270-
self.load_docstring(doc_str);
1271-
emit!(self, Instruction::Rotate2);
1272-
let doc = self.name("__doc__");
1273-
emit!(self, Instruction::StoreAttr { idx: doc });
1269+
if let Some(value) = doc_str {
1270+
emit!(self, Instruction::Duplicate);
1271+
self.emit_constant(ConstantData::Str { value });
1272+
emit!(self, Instruction::Rotate2);
1273+
let doc = self.name("__doc__");
1274+
emit!(self, Instruction::StoreAttr { idx: doc });
1275+
}
12741276

12751277
self.apply_decorators(decorator_list);
12761278

0 commit comments

Comments
 (0)