def get_category(attr):
if inspect.isclass(attr):
return EXCEPTION if issubclass(attr, Exception) else CLASS
elif inspect.isfunction(attr):
return FUNCTION
elif inspect.ismethod(attr):
return FUNCTION
elif inspect.isbuiltin(attr):
return FUNCTION
elif isinstance(attr, method_descriptor):
# Technically, method_descriptor is descriptor, but since they
# act as functions, let's treat them as functions.
return FUNCTION
elif is_descriptor(attr):
# Maybe add getsetdescriptor memberdescriptor in the future.
return DESCRIPTOR
else:
return DEFAULT_CATEGORY
评论列表
文章目录