comparison roundup/anypy/findargspec.py @ 5269:c94fd717e28c

Fix http://issues.roundup-tracker.org/issue2550952 make __call__ method of a class usable as a check function.
author John Rouillard <rouilj@ieee.org>
date Tue, 19 Sep 2017 22:00:20 -0400
parents
children c588e64718fc
comparison
equal deleted inserted replaced
5268:cc79c0f1651d 5269:c94fd717e28c
1 ''' Wrapper for getargspec to support other callables and python 3 support
2
3 In python 3 just uses getfullargspec which handles regular functions
4 and classes with __call__ methods.
5 '''
6
7 try:
8 # Python 3+
9 from inspect import getfullargspec as getargspec
10 findargspec = getargspec
11 except:
12 # Python 2.5-2.7 modified from https://bugs.python.org/issue20828
13 import inspect
14
15 def findargspec(fn):
16 if inspect.isfunction(fn) or inspect.ismethod(fn):
17 inspectable = fn
18 elif inspect.isclass(fn):
19 inspectable = fn.__init__
20 elif hasattr(fn, '__call__'):
21 inspectable = fn.__call__
22 else:
23 inspectable = fn
24
25 try:
26 return inspect.getargspec(inspectable)
27 except TypeError:
28 raise

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