Update generate_object_report() to handle slots

This commit is contained in:
2Shirt 2022-04-04 18:31:15 -06:00
parent 172cb398ba
commit 56e145942a
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

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