@@ -200,42 +200,30 @@ def _get_base_classes(frame, namespace):
200
200
201
201
def _get_base_class_names (frame : FrameType ) -> List [List [str ]]:
202
202
"""Get baseclass names from the code object"""
203
- extends : List [Tuple [str , str ]] = []
204
- add_last_step = True
203
+ current_item : List [str ] = []
204
+ items : List [List [str ]] = []
205
+
205
206
for instruction in dis .get_instructions (frame .f_code ):
207
+ print (f"{ instruction .offset } : { instruction .opname } { instruction .argval } " )
206
208
if instruction .offset > frame .f_lasti :
207
209
break
208
210
if instruction .opcode not in dis .hasname :
209
211
continue
210
- if not add_last_step :
211
- extends = []
212
- add_last_step = True
213
212
214
213
# Combine LOAD_NAME and LOAD_GLOBAL as they have similar functionality
215
214
if instruction .opname in ["LOAD_NAME" , "LOAD_GLOBAL" ]:
216
- extends . append (( "name" , instruction .argval ))
215
+ current_item = [ instruction .argval ]
217
216
218
- elif instruction .opname == "LOAD_ATTR" and extends and extends [ - 1 ][ 0 ] == "name" :
219
- extends .append (( "attr" , instruction .argval ) )
217
+ elif instruction .opname == "LOAD_ATTR" and current_item :
218
+ current_item .append (instruction .argval )
220
219
221
220
# Reset on other instructions
222
- else :
223
- add_last_step = False
224
-
225
- # Extracting class names
226
- items : List [List [str ]] = []
227
- previous_item : List [str ] = []
228
- for t , s in extends :
229
- if t == "name" :
230
- if previous_item :
231
- items .append (previous_item )
232
- previous_item = [s ]
233
- else :
234
- previous_item += [s ]
235
-
236
- if previous_item :
237
- items .append (previous_item )
221
+ elif current_item :
222
+ items .append (current_item )
223
+ current_item = []
238
224
225
+ if current_item :
226
+ items .append (current_item )
239
227
return items
240
228
241
229
0 commit comments