@@ -341,6 +341,10 @@ def test_lambda_doc(self):
341
341
l = lambda : "foo"
342
342
self .assertIsNone (l .__doc__ )
343
343
344
+ def test_lambda_consts (self ):
345
+ l = lambda : "this is the only const"
346
+ self .assertEqual (len (l .__code__ .co_consts ), 1 )
347
+
344
348
def test_encoding (self ):
345
349
code = b'# -*- coding: badencoding -*-\n pass\n '
346
350
self .assertRaises (SyntaxError , compile , code , 'tmp' , 'exec' )
@@ -789,10 +793,10 @@ def check_same_constant(const):
789
793
# Merge constants in tuple or frozenset
790
794
f1 , f2 = lambda : "not a name" , lambda : ("not a name" ,)
791
795
f3 = lambda x : x in {("not a name" ,)}
792
- self .assertIs (f1 .__code__ .co_consts [1 ],
793
- f2 .__code__ .co_consts [1 ][0 ])
794
- self .assertIs (next (iter (f3 .__code__ .co_consts [1 ])),
795
- f2 .__code__ .co_consts [1 ])
796
+ self .assertIs (f1 .__code__ .co_consts [0 ],
797
+ f2 .__code__ .co_consts [0 ][0 ])
798
+ self .assertIs (next (iter (f3 .__code__ .co_consts [0 ])),
799
+ f2 .__code__ .co_consts [0 ])
796
800
797
801
# {0} is converted to a constant frozenset({0}) by the peephole
798
802
# optimizer
0 commit comments