Skip to content

Commit 848727b

Browse files
committed
objtype: Set __doc__ as None if not included
This set __doc__ as None if it is not included in attribute while making new instance of type. In cpython if there is no docstring in class definition, __doc__ attribute will be None. So RustPython should follow it. Partially solves RustPython#1523
1 parent ff54fc8 commit 848727b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

vm/src/obj/objtype.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,12 @@ fn type_new_slot(metatype: PyClassRef, args: PyFuncArgs, vm: &VirtualMachine) ->
321321
bases
322322
};
323323

324-
let attributes = dict.to_attributes();
324+
let mut attributes = dict.to_attributes();
325+
326+
// insert __doc__ as None if it is not included in attributes
327+
if !attributes.contains_key("__doc__") {
328+
attributes.insert("__doc__".to_string(), vm.ctx.none());
329+
}
325330

326331
let mut winner = metatype.clone();
327332
for base in &bases {

0 commit comments

Comments
 (0)