瀏覽代碼

Cosmetics

Ask Solem 9 年之前
父節點
當前提交
04aa0e986b
共有 4 個文件被更改,包括 12 次插入6 次删除
  1. 1 1
      celery/app/task.py
  2. 1 1
      celery/canvas.py
  3. 4 4
      celery/result.py
  4. 6 0
      celery/utils/abstract.py

+ 1 - 1
celery/app/task.py

@@ -120,6 +120,7 @@ class Context(object):
         return self._children
 
 
+@abstract.CallableTask.register
 @python_2_unicode_compatible
 class Task(object):
     """Task base class.
@@ -940,5 +941,4 @@ class Task(object):
     @property
     def __name__(self):
         return self.__class__.__name__
-abstract.CallableTask.register(Task)
 BaseTask = Task  # compat alias

+ 1 - 1
celery/canvas.py

@@ -120,6 +120,7 @@ def _upgrade(fields, sig):
     return sig
 
 
+@abstract.CallableSignature.register
 @python_2_unicode_compatible
 class Signature(dict):
     """Class that wraps the arguments and execution options
@@ -395,7 +396,6 @@ class Signature(dict):
     subtask_type = _getitem_property('subtask_type')
     chord_size = _getitem_property('chord_size')
     immutable = _getitem_property('immutable')
-abstract.CallableSignature.register(Signature)
 
 
 @Signature.register_type

+ 4 - 4
celery/result.py

@@ -67,6 +67,7 @@ class ResultBase(object):
     parent = None
 
 
+@Thenable.register
 @python_2_unicode_compatible
 class AsyncResult(ResultBase):
     """Query task state.
@@ -437,9 +438,9 @@ class AsyncResult(ResultBase):
     @task_id.setter  # noqa
     def task_id(self, id):
         self.id = id
-Thenable.register(AsyncResult)
 
 
+@Thenable.register
 @python_2_unicode_compatible
 class ResultSet(ResultBase):
     """Working with more than one result.
@@ -803,9 +804,9 @@ class ResultSet(ResultBase):
     @property
     def backend(self):
         return self.app.backend if self.app else self.results[0].backend
-Thenable.register(ResultSet)
 
 
+@Thenable.register
 @python_2_unicode_compatible
 class GroupResult(ResultSet):
     """Like :class:`ResultSet`, but with an associated id.
@@ -882,9 +883,9 @@ class GroupResult(ResultSet):
         return (
             backend or (self.app.backend if self.app else current_app.backend)
         ).restore_group(id)
-Thenable.register(ResultSet)
 
 
+@Thenable.register
 @python_2_unicode_compatible
 class EagerResult(AsyncResult):
     """Result that we know has already been executed."""
@@ -961,7 +962,6 @@ class EagerResult(AsyncResult):
     @property
     def supports_native_join(self):
         return False
-Thenable.register(EagerResult)
 
 
 def result_from_tuple(r, app=None):

+ 6 - 0
celery/utils/abstract.py

@@ -31,6 +31,12 @@ class _AbstractClass(object):
             all(_hasattr(C, attr) for attr in cls.__required_attributes__)
         ) or NotImplemented
 
+    @classmethod
+    def register(cls, other):
+        # we override `register` to return other for use as a decorator.
+        type(cls).register(cls, other)
+        return other
+
 
 class CallableTask(_AbstractClass, Callable):  # pragma: no cover
     __required_attributes__ = frozenset({