comparison roundup/anypy/findargspec.py @ 6021:c588e64718fc

flake8 fixes. use except ImportError; use callable() not hasattr(x, '__call__')
author John Rouillard <rouilj@ieee.org>
date Thu, 02 Jan 2020 20:50:41 -0500
parents c94fd717e28c
children
comparison
equal deleted inserted replaced
6020:aa26a260e81c 6021:c588e64718fc
6 6
7 try: 7 try:
8 # Python 3+ 8 # Python 3+
9 from inspect import getfullargspec as getargspec 9 from inspect import getfullargspec as getargspec
10 findargspec = getargspec 10 findargspec = getargspec
11 except: 11 except ImportError:
12 # Python 2.5-2.7 modified from https://bugs.python.org/issue20828 12 # Python 2.5-2.7 modified from https://bugs.python.org/issue20828
13 import inspect 13 import inspect
14 14
15 def findargspec(fn): 15 def findargspec(fn):
16 if inspect.isfunction(fn) or inspect.ismethod(fn): 16 if inspect.isfunction(fn) or inspect.ismethod(fn):
17 inspectable = fn 17 inspectable = fn
18 elif inspect.isclass(fn): 18 elif inspect.isclass(fn):
19 inspectable = fn.__init__ 19 inspectable = fn.__init__
20 elif hasattr(fn, '__call__'): 20 elif callable(fn):
21 inspectable = fn.__call__ 21 inspectable = fn.__call__
22 else: 22 else:
23 inspectable = fn 23 inspectable = fn
24 24
25 try: 25 try:

Roundup Issue Tracker: http://roundup-tracker.org/