File tree 2 files changed +19
-13
lines changed
2 files changed +19
-13
lines changed Original file line number Diff line number Diff line change @@ -1015,22 +1015,23 @@ impl<O: OutputStream> Compiler<O> {
1015
1015
}
1016
1016
1017
1017
fn store_docstring ( & mut self , doc_str : Option < String > ) {
1018
- if let Some ( doc_string) = doc_str {
1019
- // Duplicate top of stack (the function or class object)
1020
- self . emit ( Instruction :: Duplicate ) ;
1018
+ // Duplicate top of stack (the function or class object)
1019
+ self . emit ( Instruction :: Duplicate ) ;
1021
1020
1022
- // Doc string value:
1023
- self . emit ( Instruction :: LoadConst {
1024
- value : bytecode:: Constant :: String {
1025
- value : doc_string. to_string ( ) ,
1021
+ // Doc string value:
1022
+ self . emit ( Instruction :: LoadConst {
1023
+ value : match doc_str {
1024
+ Some ( doc) => bytecode:: Constant :: String {
1025
+ value : doc. to_string ( ) ,
1026
1026
} ,
1027
- } ) ;
1027
+ None => bytecode:: Constant :: None , // set docstring None if not declared
1028
+ } ,
1029
+ } ) ;
1028
1030
1029
- self . emit ( Instruction :: Rotate { amount : 2 } ) ;
1030
- self . emit ( Instruction :: StoreAttr {
1031
- name : "__doc__" . to_string ( ) ,
1032
- } ) ;
1033
- }
1031
+ self . emit ( Instruction :: Rotate { amount : 2 } ) ;
1032
+ self . emit ( Instruction :: StoreAttr {
1033
+ name : "__doc__" . to_string ( ) ,
1034
+ } ) ;
1034
1035
}
1035
1036
1036
1037
fn compile_while (
Original file line number Diff line number Diff line change @@ -95,3 +95,8 @@ def f8() -> int:
95
95
96
96
with assert_raises (SyntaxError ):
97
97
exec ('print(keyword=10, 20)' )
98
+
99
+ def f9 ():
100
+ pass
101
+
102
+ assert f9 .__doc__ == None
You can’t perform that action at this time.
0 commit comments