Browse Source

Adds .five.getfullargspec

Ask Solem 9 years ago
parent
commit
b0a9990ead
4 changed files with 12 additions and 15 deletions
  1. 2 3
      celery/bin/base.py
  2. 2 6
      celery/contrib/sphinx.py
  3. 5 0
      celery/five.py
  4. 3 6
      celery/utils/functional.py

+ 2 - 3
celery/bin/base.py

@@ -79,7 +79,6 @@ import json
 
 from collections import defaultdict
 from heapq import heappush
-from inspect import getargspec
 from optparse import (
     OptionParser, OptionGroup, IndentedHelpFormatter, make_option as Option,
 )
@@ -88,7 +87,7 @@ from pprint import pformat
 from celery import VERSION_BANNER, Celery, maybe_patch_concurrency
 from celery import signals
 from celery.exceptions import CDeprecationWarning, CPendingDeprecationWarning
-from celery.five import items, string, string_t
+from celery.five import getfullargspec, items, string, string_t
 from celery.platforms import EX_FAILURE, EX_OK, EX_USAGE
 from celery.utils import term
 from celery.utils import text
@@ -283,7 +282,7 @@ class Command(object):
             return exc.status
 
     def verify_args(self, given, _index=0):
-        S = getargspec(self.run)
+        S = getfullargspec(self.run)
         _index = 1 if S.args and S.args[0] == 'self' else _index
         required = S.args[_index:-len(S.defaults) if S.defaults else None]
         missing = required[len(given):]

+ 2 - 6
celery/contrib/sphinx.py

@@ -32,15 +32,11 @@ Use ``.. autotask::`` to manually document a task.
 """
 from __future__ import absolute_import
 
-try:
-    from inspect import formatargspec, getfullargspec as getargspec
-except ImportError:  # Py2
-    from inspect import formatargspec, getargspec  # noqa
-
 from sphinx.domains.python import PyModulelevel
 from sphinx.ext.autodoc import FunctionDocumenter
 
 from celery.app.task import BaseTask
+from celery.five import formatargspec, getfullargspec
 
 
 class TaskDocumenter(FunctionDocumenter):
@@ -54,7 +50,7 @@ class TaskDocumenter(FunctionDocumenter):
     def format_args(self):
         wrapped = getattr(self.object, '__wrapped__')
         if wrapped is not None:
-            argspec = getargspec(wrapped)
+            argspec = getfullargspec(wrapped)
             fmt = formatargspec(*argspec)
             fmt = fmt.replace('\\', '\\\\')
             return fmt

+ 5 - 0
celery/five.py

@@ -25,6 +25,11 @@ try:
 except ImportError:
     pass
 
+try:  # pragma: no cover
+    from inspect import formatargspec, getfullargspec
+except ImportError:  # Py2
+    from inspect import formatargspec, getargspec as getfullargspec  # noqa
+
 __all__ = [
     'class_property', 'reclassmethod', 'create_module', 'recreate_module',
 ]

+ 3 - 6
celery/utils/functional.py

@@ -13,10 +13,7 @@ import threading
 
 from collections import OrderedDict
 from functools import partial, wraps
-try:
-    from inspect import isfunction, getfullargspec as getargspec
-except ImportError:  # Py2
-    from inspect import isfunction, getargspec  # noqa
+from inspect import isfunction
 from itertools import chain, islice
 
 from kombu.utils.functional import (
@@ -24,7 +21,7 @@ from kombu.utils.functional import (
 )
 from vine import promise
 
-from celery.five import UserDict, UserList, keys, range
+from celery.five import UserDict, UserList, getfullargspec, keys, range
 
 __all__ = ['LRUCache', 'is_list', 'maybe_list', 'memoize', 'mlazy', 'noop',
            'first', 'firstmethod', 'chunks', 'padlist', 'mattrgetter', 'uniq',
@@ -388,7 +385,7 @@ def head_from_fun(fun, bound=False, debug=False):
         name = fun.__name__
     definition = FUNHEAD_TEMPLATE.format(
         fun_name=name,
-        fun_args=_argsfromspec(getargspec(fun)),
+        fun_args=_argsfromspec(getfullargspec(fun)),
         fun_value=1,
     )
     if debug:  # pragma: no cover