Simplify utils.qualname, take two.

This commit is contained in:
Florian Bruhin 2015-08-04 10:39:34 +02:00
parent c67f7b6b21
commit 7e7fe9b4ce

View File

@ -22,7 +22,6 @@
import io import io
import sys import sys
import enum import enum
import inspect
import os.path import os.path
import collections import collections
import functools import functools
@ -548,18 +547,18 @@ def qualname(obj):
""" """
if isinstance(obj, functools.partial): if isinstance(obj, functools.partial):
obj = obj.func obj = obj.func
if hasattr(obj, '__qualname__'):
name = obj.__qualname__
elif hasattr(obj, '__name__'):
name = obj.__name__
else:
name = repr(obj)
if (inspect.isclass(obj) or inspect.isfunction(obj) or if hasattr(obj, '__module__'):
inspect.ismethod(obj)): prefix = '{}.'.format(obj.__module__)
return "{}.{}".format(obj.__module__, name)
else: else:
return name prefix = ''
if hasattr(obj, '__qualname__'):
return '{}{}'.format(prefix, obj.__qualname__)
elif hasattr(obj, '__name__'):
return '{}{}'.format(prefix, obj.__name__)
else:
return repr(obj)
def raises(exc, func, *args): def raises(exc, func, *args):