Better debugging output for is_sub_class_of

This commit is contained in:
Dave Halter
2020-06-14 17:55:49 +02:00
parent 674e0114a5
commit 1d1c0ec3af
2 changed files with 11 additions and 7 deletions

View File

@@ -84,17 +84,17 @@ def increase_indent(func):
@contextmanager
def increase_indent_cm(title=None):
def increase_indent_cm(title=None, color='MAGENTA'):
global _debug_indent
if title:
dbg('Start: ' + title, color='MAGENTA')
dbg('Start: ' + title, color=color)
_debug_indent += 1
try:
yield
finally:
_debug_indent -= 1
if title:
dbg('End: ' + title, color='MAGENTA')
dbg('End: ' + title, color=color)
def dbg(message, *args, **kwargs):

View File

@@ -114,10 +114,14 @@ class HelperValueMixin(object):
return self.py__iter__(contextualized_node)
def is_sub_class_of(self, class_value):
for cls in self.py__mro__():
if cls.is_same_class(class_value):
return True
return False
with debug.increase_indent_cm('subclass matching of %s <=> %s' % (self, class_value),
color='BLUE'):
for cls in self.py__mro__():
if cls.is_same_class(class_value):
debug.dbg('matched subclass True', color='BLUE')
return True
debug.dbg('matched subclass False', color='BLUE')
return False
def is_same_class(self, class2):
# Class matching should prefer comparisons that are not this function.