summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <jxharlow@godaddy.com>2016-11-01 11:00:56 -0700
committerJoshua Harlow <jxharlow@godaddy.com>2016-11-01 11:02:44 -0700
commit4eeee2a641538d55d0ab006c61f85d234832efae (patch)
tree969e8a88a585863b9fd4c0634f972b17b39fa34f
parent2b36107f0b6b03c79d184f995dfee4c761d38350 (diff)
downloadoslo-utils-4eeee2a641538d55d0ab006c61f85d234832efae.tar.gz
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
-rw-r--r--oslo_utils/reflection.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/oslo_utils/reflection.py b/oslo_utils/reflection.py
index b0dcada..ef2563a 100644
--- a/oslo_utils/reflection.py
+++ b/oslo_utils/reflection.py
@@ -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: