"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/roundup/anypy/findargspec.py" (29 Feb 2020, 800 Bytes) of package /linux/www/roundup-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "findargspec.py": 1.6.1_vs_2.0.0.

    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 ImportError:
   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 callable(fn):
   21             inspectable = fn.__call__
   22         else:
   23             inspectable = fn
   24 
   25         try:
   26             return inspect.getargspec(inspectable)
   27         except TypeError:
   28             raise