@@ -431,18 +431,6 @@ def foo(a: int, b: str) -> str:
431
431
RETURN_VALUE
432
432
"""
433
433
434
- issue_135700 = """\
435
- 22
436
- 333
437
- __dataclass_fields__: ClassVar
438
- """
439
-
440
- issue_135700_class = """\
441
- class _B:
442
- 2
443
- c: int
444
- """
445
-
446
434
compound_stmt_str = """\
447
435
x = 0
448
436
while 1:
@@ -1138,25 +1126,44 @@ def test_bug_46724(self):
1138
1126
1139
1127
def test_annotate_no_spurious_first_node_positions (self ):
1140
1128
# Test that __annotate__ code doesn't inherit first AST node positions
1129
+ issue_135700 = "1\n x: int"
1130
+ issue_135700_class = "class A:\n 1\n x: int"
1131
+
1141
1132
test_cases = [
1142
1133
("module" , compile (issue_135700 , "<string>" , "exec" ).co_consts [1 ]),
1143
- ("class" , compile (ast .parse (issue_135700_class ), "?" , "exec" ).co_consts [0 ].co_consts [1 ])
1134
+ (
1135
+ "class" ,
1136
+ compile (ast .parse (issue_135700_class ), "?" , "exec" )
1137
+ .co_consts [0 ]
1138
+ .co_consts [1 ],
1139
+ ),
1144
1140
]
1145
1141
1146
1142
for case_name , annotate_code in test_cases :
1147
1143
with self .subTest (case = case_name ):
1148
1144
instructions = list (dis .Bytecode (annotate_code ))
1149
-
1150
- spurious_positions = sum (
1151
- 1 for instr in instructions
1152
- if (instr .positions and
1153
- instr .positions .lineno == 1 and
1154
- instr .positions .col_offset == 0 and
1155
- instr .positions .end_col_offset == 1 )
1145
+ print (instructions )
1146
+ resume_pos = next (
1147
+ (
1148
+ inst .positions
1149
+ for inst in instructions
1150
+ if inst .opname == "RESUME"
1151
+ ),
1152
+ None ,
1156
1153
)
1157
-
1158
- self .assertEqual (spurious_positions , 0 ,
1159
- f"No instructions in { case_name } __annotate__ should have first statement's position" )
1154
+ for instruction in instructions :
1155
+ if instruction .opname == "BUILD_MAP" :
1156
+ break
1157
+ if (
1158
+ instruction .opname != "RESUME"
1159
+ and instruction .positions
1160
+ and instruction .positions .lineno
1161
+ ):
1162
+ self .assertEqual (
1163
+ instruction .positions ,
1164
+ resume_pos ,
1165
+ f"{ case_name } : Unexpected position { instruction .positions } in { instruction .opname } , expected { resume_pos } " ,
1166
+ )
1160
1167
1161
1168
def test_kw_names (self ):
1162
1169
# Test that value is displayed for keyword argument names:
0 commit comments