Add option to not truncate built-ins

In certain cases it is actually useful to have the
full module name for built-ins so make it possible
to not always truncate it.

Change-Id: Ifb9218054605c8952e3895b6b4d51552231c0476
This commit is contained in:
Joshua Harlow 2016-11-01 11:00:56 -07:00
parent 2b36107f0b
commit 4eeee2a641

View File

@ -64,7 +64,7 @@ def get_member_names(obj, exclude_hidden=True):
get_members(obj, exclude_hidden=exclude_hidden)] get_members(obj, exclude_hidden=exclude_hidden)]
def get_class_name(obj, fully_qualified=True): def get_class_name(obj, fully_qualified=True, truncate_builtins=True):
"""Get class name for object. """Get class name for object.
If object is a type, returns name of the type. If object is a bound If object is a type, returns name of the type. If object is a bound
@ -82,14 +82,14 @@ def get_class_name(obj, fully_qualified=True):
obj = get_method_self(obj) obj = get_method_self(obj)
if not isinstance(obj, six.class_types): if not isinstance(obj, six.class_types):
obj = type(obj) obj = type(obj)
try: if truncate_builtins:
built_in = obj.__module__ in _BUILTIN_MODULES try:
except AttributeError: # nosec built_in = obj.__module__ in _BUILTIN_MODULES
pass except AttributeError: # nosec
else: pass
if built_in: else:
return obj.__name__ if built_in:
return obj.__name__
if fully_qualified and hasattr(obj, '__module__'): if fully_qualified and hasattr(obj, '__module__'):
return '%s.%s' % (obj.__module__, obj.__name__) return '%s.%s' % (obj.__module__, obj.__name__)
else: else: