@@ -613,7 +613,7 @@ def check_same_constant(const):
613
613
exec (code , ns )
614
614
f1 = ns ['f1' ]
615
615
f2 = ns ['f2' ]
616
- self .assertIs (f1 .__code__ , f2 .__code__ )
616
+ self .assertIs (f1 .__code__ . co_consts , f2 .__code__ . co_consts )
617
617
self .check_constant (f1 , const )
618
618
self .assertEqual (repr (f1 ()), repr (const ))
619
619
@@ -626,7 +626,7 @@ def check_same_constant(const):
626
626
# Note: "lambda: ..." emits "LOAD_CONST Ellipsis",
627
627
# whereas "lambda: Ellipsis" emits "LOAD_GLOBAL Ellipsis"
628
628
f1 , f2 = lambda : ..., lambda : ...
629
- self .assertIs (f1 .__code__ , f2 .__code__ )
629
+ self .assertIs (f1 .__code__ . co_consts , f2 .__code__ . co_consts )
630
630
self .check_constant (f1 , Ellipsis )
631
631
self .assertEqual (repr (f1 ()), repr (Ellipsis ))
632
632
@@ -641,7 +641,7 @@ def check_same_constant(const):
641
641
# {0} is converted to a constant frozenset({0}) by the peephole
642
642
# optimizer
643
643
f1 , f2 = lambda x : x in {0 }, lambda x : x in {0 }
644
- self .assertIs (f1 .__code__ , f2 .__code__ )
644
+ self .assertIs (f1 .__code__ . co_consts , f2 .__code__ . co_consts )
645
645
self .check_constant (f1 , frozenset ({0 }))
646
646
self .assertTrue (f1 (0 ))
647
647
@@ -1264,6 +1264,27 @@ def f():
1264
1264
self .assertIsNotNone (end_column )
1265
1265
self .assertLessEqual ((line , column ), (end_line , end_column ))
1266
1266
1267
+ @support .cpython_only
1268
+ def test_column_offset_deduplication (self ):
1269
+ # GH-95150: Code with different column offsets shouldn't be merged!
1270
+ for source in [
1271
+ "lambda: a" ,
1272
+ "(a for b in c)" ,
1273
+ "[a for b in c]" ,
1274
+ "{a for b in c}" ,
1275
+ "{a: b for c in d}" ,
1276
+ ]:
1277
+ with self .subTest (source ):
1278
+ code = compile (f"{ source } , { source } " , "<test>" , "eval" )
1279
+ self .assertEqual (len (code .co_consts ), 2 )
1280
+ self .assertIsInstance (code .co_consts [0 ], types .CodeType )
1281
+ self .assertIsInstance (code .co_consts [1 ], types .CodeType )
1282
+ self .assertNotEqual (code .co_consts [0 ], code .co_consts [1 ])
1283
+ self .assertNotEqual (
1284
+ list (code .co_consts [0 ].co_positions ()),
1285
+ list (code .co_consts [1 ].co_positions ()),
1286
+ )
1287
+
1267
1288
1268
1289
class TestExpressionStackSize (unittest .TestCase ):
1269
1290
# These tests check that the computed stack size for a code object
0 commit comments