mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-15 17:15:24 +00:00
Merge pull request #1580 from seeeturtle/doc-f
Set docstring of function as None if not declared
This commit is contained in:
commit
47c8f3756b
1 changed files with 14 additions and 13 deletions
|
@ -1015,22 +1015,23 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_docstring(&mut self, doc_str: Option<String>) {
|
fn store_docstring(&mut self, doc_str: Option<String>) {
|
||||||
if let Some(doc_string) = doc_str {
|
// Duplicate top of stack (the function or class object)
|
||||||
// Duplicate top of stack (the function or class object)
|
self.emit(Instruction::Duplicate);
|
||||||
self.emit(Instruction::Duplicate);
|
|
||||||
|
|
||||||
// Doc string value:
|
// Doc string value:
|
||||||
self.emit(Instruction::LoadConst {
|
self.emit(Instruction::LoadConst {
|
||||||
value: bytecode::Constant::String {
|
value: match doc_str {
|
||||||
value: doc_string.to_string(),
|
Some(doc) => bytecode::Constant::String {
|
||||||
|
value: doc.to_string(),
|
||||||
},
|
},
|
||||||
});
|
None => bytecode::Constant::None, // set docstring None if not declared
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
self.emit(Instruction::Rotate { amount: 2 });
|
self.emit(Instruction::Rotate { amount: 2 });
|
||||||
self.emit(Instruction::StoreAttr {
|
self.emit(Instruction::StoreAttr {
|
||||||
name: "__doc__".to_string(),
|
name: "__doc__".to_string(),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_while(
|
fn compile_while(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue