File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -1107,6 +1107,10 @@ impl Compiler {
11071107
11081108 let ( doc_str, body) = split_doc ( body) ;
11091109
1110+ self . current_codeinfo ( )
1111+ . constants
1112+ . insert_full ( ConstantData :: None ) ;
1113+
11101114 self . compile_statements ( body) ?;
11111115
11121116 // Emit None at end:
@@ -2122,6 +2126,11 @@ impl Compiler {
21222126
21232127 let name = "<lambda>" . to_owned ( ) ;
21242128 let mut funcflags = self . enter_function ( & name, args) ?;
2129+
2130+ self . current_codeinfo ( )
2131+ . constants
2132+ . insert_full ( ConstantData :: None ) ;
2133+
21252134 self . compile_expression ( body) ?;
21262135 self . emit ( Instruction :: ReturnValue ) ;
21272136 let code = self . pop_code_object ( ) ;
Original file line number Diff line number Diff line change 1+ from asyncio import sleep
2+
3+ def f ():
4+ def g ():
5+ return 1
6+
7+ assert g .__code__ .co_consts [0 ] == None
8+ return 2
9+
10+ assert f .__code__ .co_consts [0 ] == None
11+
12+ def generator ():
13+ yield 1
14+ yield 2
15+
16+ assert generator ().gi_code .co_consts [0 ] == None
17+
18+ async def async_f ():
19+ await sleep (1 )
20+ return 1
21+
22+ assert async_f .__code__ .co_consts [0 ] == None
23+
24+ lambda_f = lambda : 0
25+ assert lambda_f .__code__ .co_consts [0 ] == None
26+
27+ class cls :
28+ def f ():
29+ return 1
30+
31+ assert cls ().f .__code__ .co_consts [0 ] == None
You can’t perform that action at this time.
0 commit comments