@@ -349,7 +349,7 @@ impl Compiler {
349
349
let size_before = self . code_stack . len ( ) ;
350
350
self . symbol_table_stack . push ( symbol_table) ;
351
351
352
- let ( doc, statements) = split_doc ( body) ;
352
+ let ( doc, statements) = split_doc ( body, & self . opts ) ;
353
353
if let Some ( value) = doc {
354
354
self . emit_constant ( ConstantData :: Str { value } ) ;
355
355
let doc = self . name ( "__doc__" ) ;
@@ -1187,7 +1187,7 @@ impl Compiler {
1187
1187
let qualified_name = self . qualified_path . join ( "." ) ;
1188
1188
self . push_qualified_path ( "<locals>" ) ;
1189
1189
1190
- let ( doc_str, body) = split_doc ( body) ;
1190
+ let ( doc_str, body) = split_doc ( body, & self . opts ) ;
1191
1191
1192
1192
self . current_code_info ( )
1193
1193
. constants
@@ -1383,7 +1383,7 @@ impl Compiler {
1383
1383
1384
1384
self . push_output ( bytecode:: CodeFlags :: empty ( ) , 0 , 0 , 0 , name. to_owned ( ) ) ;
1385
1385
1386
- let ( doc_str, body) = split_doc ( body) ;
1386
+ let ( doc_str, body) = split_doc ( body, & self . opts ) ;
1387
1387
1388
1388
let dunder_name = self . name ( "__name__" ) ;
1389
1389
emit ! ( self , Instruction :: LoadGlobal ( dunder_name) ) ;
@@ -2875,10 +2875,17 @@ impl EmitArg<bytecode::Label> for ir::BlockIdx {
2875
2875
}
2876
2876
}
2877
2877
2878
- fn split_doc ( body : & [ located_ast:: Stmt ] ) -> ( Option < String > , & [ located_ast:: Stmt ] ) {
2878
+ fn split_doc < ' a > (
2879
+ body : & ' a [ located_ast:: Stmt ] ,
2880
+ opts : & CompileOpts ,
2881
+ ) -> ( Option < String > , & ' a [ located_ast:: Stmt ] ) {
2879
2882
if let Some ( ( located_ast:: Stmt :: Expr ( expr) , body_rest) ) = body. split_first ( ) {
2880
2883
if let Some ( doc) = try_get_constant_string ( std:: slice:: from_ref ( & expr. value ) ) {
2881
- return ( Some ( doc) , body_rest) ;
2884
+ if opts. optimize < 2 {
2885
+ return ( Some ( doc) , body_rest) ;
2886
+ } else {
2887
+ return ( None , body_rest) ;
2888
+ }
2882
2889
}
2883
2890
}
2884
2891
( None , body)
0 commit comments