Skip to content

Commit f4cf3ed

Browse files
committed
bytecode resolution
1 parent ccafd5a commit f4cf3ed

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

overrides/overrides.py

+12-24
Original file line numberDiff line numberDiff line change
@@ -200,42 +200,30 @@ def _get_base_classes(frame, namespace):
200200

201201
def _get_base_class_names(frame: FrameType) -> List[List[str]]:
202202
"""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+
205206
for instruction in dis.get_instructions(frame.f_code):
207+
print(f"{instruction.offset} : {instruction.opname} {instruction.argval}")
206208
if instruction.offset > frame.f_lasti:
207209
break
208210
if instruction.opcode not in dis.hasname:
209211
continue
210-
if not add_last_step:
211-
extends = []
212-
add_last_step = True
213212

214213
# Combine LOAD_NAME and LOAD_GLOBAL as they have similar functionality
215214
if instruction.opname in ["LOAD_NAME", "LOAD_GLOBAL"]:
216-
extends.append(("name", instruction.argval))
215+
current_item = [instruction.argval]
217216

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)
220219

221220
# 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 = []
238224

225+
if current_item:
226+
items.append(current_item)
239227
return items
240228

241229

tests/test_overrides.py

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def some_method(self):
5454
"""Subber"""
5555
return 1
5656

57+
5758
class Nest:
5859
class First:
5960
class Second:
@@ -96,6 +97,7 @@ class SomeClass:
9697
def check(self):
9798
return 1
9899

100+
99101
class ChildOfNested(Nest.First.Second):
100102
@override
101103
def foo(self):

0 commit comments

Comments
 (0)