Update generate_object_report() to handle slots
This commit is contained in:
parent
172cb398ba
commit
56e145942a
1 changed files with 10 additions and 3 deletions
|
|
@ -20,13 +20,20 @@ METHOD_TYPE = type(DEBUG_CLASS.method)
|
||||||
def generate_object_report(obj, indent=0):
|
def generate_object_report(obj, indent=0):
|
||||||
"""Generate debug report for obj, returns list."""
|
"""Generate debug report for obj, returns list."""
|
||||||
report = []
|
report = []
|
||||||
|
attr_list = []
|
||||||
|
|
||||||
|
# Get attribute list
|
||||||
|
if hasattr(obj, '__slots__'):
|
||||||
|
attr_list = list(obj.__slots__)
|
||||||
|
else:
|
||||||
|
attr_list = [name for name in dir(obj) if not name.startswith('_')]
|
||||||
|
|
||||||
# Dump object data
|
# Dump object data
|
||||||
for name in dir(obj):
|
for name in attr_list:
|
||||||
attr = getattr(obj, name)
|
attr = getattr(obj, name)
|
||||||
|
|
||||||
# Skip methods and private attributes
|
# Skip methods
|
||||||
if isinstance(attr, METHOD_TYPE) or name.startswith('_'):
|
if isinstance(attr, METHOD_TYPE):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Add attribute to report (expanded if necessary)
|
# Add attribute to report (expanded if necessary)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue