Browse Source

Rename curry -> partial

Ask Solem 14 years ago
parent
commit
77eb02f4f5

+ 0 - 1
celery/backends/__init__.py

@@ -1,6 +1,5 @@
 from celery.app import app_or_default
 from celery.app import app_or_default
 from celery.utils import get_cls_by_name
 from celery.utils import get_cls_by_name
-from celery.utils.functional import curry
 
 
 BACKEND_ALIASES = {
 BACKEND_ALIASES = {
     "amqp": "celery.backends.amqp.AMQPBackend",
     "amqp": "celery.backends.amqp.AMQPBackend",

+ 3 - 3
celery/concurrency/processes/__init__.py

@@ -7,7 +7,7 @@ from time import sleep, time
 
 
 from celery import log
 from celery import log
 from celery.datastructures import ExceptionInfo
 from celery.datastructures import ExceptionInfo
-from celery.utils.functional import curry
+from celery.utils.functional import partial
 
 
 from celery.concurrency.processes.pool import Pool, RUN
 from celery.concurrency.processes.pool import Pool, RUN
 
 
@@ -111,8 +111,8 @@ class TaskPool(object):
         callbacks = callbacks or []
         callbacks = callbacks or []
         errbacks = errbacks or []
         errbacks = errbacks or []
 
 
-        on_ready = curry(self.on_ready, callbacks, errbacks)
-        on_worker_error = curry(self.on_worker_error, errbacks)
+        on_ready = partial(self.on_ready, callbacks, errbacks)
+        on_worker_error = partial(self.on_worker_error, errbacks)
 
 
         self.logger.debug("TaskPool: Apply %s (args:%s kwargs:%s)" % (
         self.logger.debug("TaskPool: Apply %s (args:%s kwargs:%s)" % (
             target, args, kwargs))
             target, args, kwargs))

+ 2 - 2
celery/concurrency/threads.py

@@ -3,7 +3,7 @@ import threading
 from threadpool import ThreadPool, WorkRequest
 from threadpool import ThreadPool, WorkRequest
 
 
 from celery import log
 from celery import log
-from celery.utils.functional import curry
+from celery.utils.functional import partial
 from celery.datastructures import ExceptionInfo
 from celery.datastructures import ExceptionInfo
 
 
 
 
@@ -40,7 +40,7 @@ class TaskPool(object):
         callbacks = callbacks or []
         callbacks = callbacks or []
         errbacks = errbacks or []
         errbacks = errbacks or []
 
 
-        on_ready = curry(self.on_ready, callbacks, errbacks)
+        on_ready = partial(self.on_ready, callbacks, errbacks)
 
 
         self.logger.debug("ThreadPool: Apply %s (args:%s kwargs:%s)" % (
         self.logger.debug("ThreadPool: Apply %s (args:%s kwargs:%s)" % (
             target, args, kwargs))
             target, args, kwargs))

+ 2 - 2
celery/tests/test_buckets.py

@@ -10,12 +10,12 @@ from celery.registry import TaskRegistry
 from celery.task.base import Task
 from celery.task.base import Task
 from celery.utils import timeutils
 from celery.utils import timeutils
 from celery.utils import gen_unique_id
 from celery.utils import gen_unique_id
-from celery.utils.functional import curry
+from celery.utils.functional import partial
 from celery.worker import buckets
 from celery.worker import buckets
 
 
 from celery.tests.utils import skip_if_environ
 from celery.tests.utils import skip_if_environ
 
 
-skip_if_disabled = curry(skip_if_environ("SKIP_RLIMITS"))
+skip_if_disabled = partial(skip_if_environ("SKIP_RLIMITS"))
 
 
 
 
 class MockJob(object):
 class MockJob(object):

+ 2 - 2
celery/utils/__init__.py

@@ -18,7 +18,7 @@ from carrot.utils import rpartition
 
 
 from celery.utils.compat import all, any, defaultdict
 from celery.utils.compat import all, any, defaultdict
 from celery.utils.timeutils import timedelta_seconds        # was here before
 from celery.utils.timeutils import timedelta_seconds        # was here before
-from celery.utils.functional import curry
+from celery.utils.functional import partial
 
 
 
 
 LOG_LEVELS = dict(logging._levelNames)
 LOG_LEVELS = dict(logging._levelNames)
@@ -300,7 +300,7 @@ def fun_takes_kwargs(fun, kwlist=[]):
     args, _varargs, keywords, _defaults = argspec
     args, _varargs, keywords, _defaults = argspec
     if keywords != None:
     if keywords != None:
         return kwlist
         return kwlist
-    return filter(curry(operator.contains, args), kwlist)
+    return filter(partial(operator.contains, args), kwlist)
 
 
 
 
 def get_cls_by_name(name, aliases={}):
 def get_cls_by_name(name, aliases={}):

+ 7 - 9
celery/utils/functional.py

@@ -53,8 +53,6 @@
 ### Begin from Python 2.5 functools.py ########################################
 ### Begin from Python 2.5 functools.py ########################################
 
 
 # Summary of changes made to the Python 2.5 code below:
 # Summary of changes made to the Python 2.5 code below:
-#   * swapped ``partial`` for ``curry`` to maintain backwards-compatibility
-#     in Django.
 #   * Wrapped the ``setattr`` call in ``update_wrapper`` with a try-except
 #   * Wrapped the ``setattr`` call in ``update_wrapper`` with a try-except
 #     block to make it compatible with Python 2.3, which doesn't allow
 #     block to make it compatible with Python 2.3, which doesn't allow
 #     assigning to ``__name__``.
 #     assigning to ``__name__``.
@@ -68,7 +66,7 @@
 # wrapper functions that can handle naive introspection
 # wrapper functions that can handle naive introspection
 
 
 
 
-def _compat_curry(fun, *args, **kwargs):
+def _compat_partial(fun, *args, **kwargs):
     """New function with partial application of the given arguments
     """New function with partial application of the given arguments
     and keywords."""
     and keywords."""
 
 
@@ -78,9 +76,9 @@ def _compat_curry(fun, *args, **kwargs):
 
 
 
 
 try:
 try:
-    from functools import partial as curry
+    from functools import partial
 except ImportError:
 except ImportError:
-    curry = _compat_curry
+    partial = _compat_partial
 
 
 WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
 WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
 WRAPPER_UPDATES = ('__dict__',)
 WRAPPER_UPDATES = ('__dict__',)
@@ -107,7 +105,7 @@ def _compat_update_wrapper(wrapper, wrapped, assigned=WRAPPER_ASSIGNMENTS,
             pass
             pass
     for attr in updated:
     for attr in updated:
         getattr(wrapper, attr).update(getattr(wrapped, attr))
         getattr(wrapper, attr).update(getattr(wrapped, attr))
-    # Return the wrapper so this can be used as a decorator via curry()
+    # Return the wrapper so this can be used as a decorator via partial()
     return wrapper
     return wrapper
 
 
 try:
 try:
@@ -123,12 +121,12 @@ def _compat_wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS,
     Returns a decorator that invokes update_wrapper() with the decorated
     Returns a decorator that invokes update_wrapper() with the decorated
     function as the wrapper argument and the arguments to wraps() as the
     function as the wrapper argument and the arguments to wraps() as the
     remaining arguments. Default arguments are as for update_wrapper().
     remaining arguments. Default arguments are as for update_wrapper().
-    This is a convenience function to simplify applying curry() to
+    This is a convenience function to simplify applying partial() to
     update_wrapper().
     update_wrapper().
 
 
     """
     """
-    return curry(update_wrapper, wrapped=wrapped,
-                 assigned=assigned, updated=updated)
+    return partial(update_wrapper, wrapped=wrapped,
+                   assigned=assigned, updated=updated)
 
 
 try:
 try:
     from functools import wraps
     from functools import wraps

+ 0 - 1
celery/worker/controllers.py

@@ -3,7 +3,6 @@
 Worker Controller Threads
 Worker Controller Threads
 
 
 """
 """
-import time
 import threading
 import threading
 from Queue import Empty as QueueEmpty
 from Queue import Empty as QueueEmpty