diff options
author | ChangBo Guo(gcb) <eric.guo@easystack.cn> | 2015-11-04 20:57:38 +0800 |
---|---|---|
committer | ChangBo Guo(gcb) <eric.guo@easystack.cn> | 2015-11-11 11:22:42 +0800 |
commit | 7ef6a8fbf98a5da61c40989cc63c0c2261dca98e (patch) | |
tree | b342b80fe4457dc226c6459415d7cec2219e9d07 /oslo_utils/reflection.py | |
parent | 7da2a5ba647cb2b222be0682d0c0ec707fbda131 (diff) | |
download | oslo-utils-7ef6a8fbf98a5da61c40989cc63c0c2261dca98e.tar.gz |
Fix get_class_name() on Python 3
Modify oslo_utils.reflection.get_class_name() to return the same result
on Python 2 and Python 3. Use obj.__name__ instead of obj.__qualname__
on Python 3.
Closes-Bug:1513067
Change-Id: If589ed2b67b42bcce6e920f6f7061eee5732f55b
Diffstat (limited to 'oslo_utils/reflection.py')
-rw-r--r-- | oslo_utils/reflection.py | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/oslo_utils/reflection.py b/oslo_utils/reflection.py index 34714fc..967d8cd 100644 --- a/oslo_utils/reflection.py +++ b/oslo_utils/reflection.py @@ -59,21 +59,12 @@ def get_class_name(obj, fully_qualified=True): pass else: if built_in: - try: - return obj.__qualname__ - except AttributeError: - return obj.__name__ - pieces = [] - try: - pieces.append(obj.__qualname__) - except AttributeError: - pieces.append(obj.__name__) - if fully_qualified: - try: - pieces.insert(0, obj.__module__) - except AttributeError: - pass - return '.'.join(pieces) + return obj.__name__ + + if fully_qualified and hasattr(obj, '__module__'): + return '%s.%s' % (obj.__module__, obj.__name__) + else: + return obj.__name__ def get_all_class_names(obj, up_to=object): |