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
1 changed files with 9 additions and 9 deletions

View File

@ -64,7 +64,7 @@ def get_member_names(obj, exclude_hidden=True):
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.
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)
if not isinstance(obj, six.class_types):
obj = type(obj)
try:
built_in = obj.__module__ in _BUILTIN_MODULES
except AttributeError: # nosec
pass
else:
if built_in:
return obj.__name__
if truncate_builtins:
try:
built_in = obj.__module__ in _BUILTIN_MODULES
except AttributeError: # nosec
pass
else:
if built_in:
return obj.__name__
if fully_qualified and hasattr(obj, '__module__'):
return '%s.%s' % (obj.__module__, obj.__name__)
else: