Skip to content

Commit

Permalink
Simplify utils.qualname, take two.
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Compiler committed Aug 4, 2015
1 parent c67f7b6 commit 7e7fe9b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions qutebrowser/utils/utils.py
Expand Up @@ -22,7 +22,6 @@
import io
import sys
import enum
import inspect
import os.path
import collections
import functools
Expand Down Expand Up @@ -548,18 +547,18 @@ def qualname(obj):
"""
if isinstance(obj, functools.partial):
obj = obj.func
if hasattr(obj, '__qualname__'):
name = obj.__qualname__
elif hasattr(obj, '__name__'):
name = obj.__name__

if hasattr(obj, '__module__'):
prefix = '{}.'.format(obj.__module__)
else:
name = repr(obj)
prefix = ''

if (inspect.isclass(obj) or inspect.isfunction(obj) or
inspect.ismethod(obj)):
return "{}.{}".format(obj.__module__, name)
if hasattr(obj, '__qualname__'):
return '{}{}'.format(prefix, obj.__qualname__)
elif hasattr(obj, '__name__'):
return '{}{}'.format(prefix, obj.__name__)
else:
return name
return repr(obj)


def raises(exc, func, *args):
Expand Down

0 comments on commit 7e7fe9b

Please sign in to comment.