From 83596516c66996f9ec8dd5ee8aa7450c4897ccac Mon Sep 17 00:00:00 2001 From: Mikko Korpela Date: Thu, 13 Oct 2022 21:28:02 +0300 Subject: [PATCH] should match to old --- overrides/overrides.py | 6 +++++- tests/test_get_base_class_names.py | 12 ------------ 2 files changed, 5 insertions(+), 13 deletions(-) delete mode 100644 tests/test_get_base_class_names.py diff --git a/overrides/overrides.py b/overrides/overrides.py index 1ca2997..8573ecb 100644 --- a/overrides/overrides.py +++ b/overrides/overrides.py @@ -146,11 +146,15 @@ def _get_base_classes(frame, namespace): def _get_base_class_names(frame) -> List[List[str]]: """Get baseclass names from the code object""" extends: List[Tuple[str, str]] = [] + add_last_step = True for instruction in dis.get_instructions(frame.f_code): if instruction.offset > frame.f_lasti: break if instruction.opcode not in dis.hasname: continue + if not add_last_step: + extends = [] + add_last_step = True if instruction.opname == "LOAD_NAME": extends.append(("name", instruction.argval)) elif instruction.opname == "LOAD_ATTR": @@ -158,7 +162,7 @@ def _get_base_class_names(frame) -> List[List[str]]: elif instruction.opname == "LOAD_GLOBAL": extends.append(("name", instruction.argval)) else: - extends = [] + add_last_step = False items: List[List[str]] = [] previous_item: List[str] = [] diff --git a/tests/test_get_base_class_names.py b/tests/test_get_base_class_names.py deleted file mode 100644 index b17d9ab..0000000 --- a/tests/test_get_base_class_names.py +++ /dev/null @@ -1,12 +0,0 @@ -import sys -import unittest - -from overrides.overrides import _get_base_class_names - -class MyTestClass(unittest.TestCase): - def test_base_classing(self): - assert _get_base_class_names(sys._getframe(0)) == [['sys', '_getframe'], ['_get_base_class_names']] - assert _get_base_class_names(sys._getframe(1)) == [] - assert _get_base_class_names(sys._getframe(2)) == [['testPartExecutor']] - assert _get_base_class_names(sys._getframe(3)) == [['run']] - assert _get_base_class_names(sys._getframe(4)) == [['setattr', '_testcase'], ['setattr', '_testcase', 'name', 'obj', '_testcase']]