Explorar o código

Use callable() now that it is allowed again (Issue #1678)

Ask Solem %!s(int64=11) %!d(string=hai) anos
pai
achega
8b00e1e1f8

+ 1 - 3
celery/app/__init__.py

@@ -10,8 +10,6 @@ from __future__ import absolute_import
 
 import os
 
-from collections import Callable
-
 from celery.local import Proxy
 from celery import _state
 from celery._state import (
@@ -148,6 +146,6 @@ def shared_task(*args, **kwargs):
             return Proxy(task_by_cons)
         return __inner
 
-    if len(args) == 1 and isinstance(args[0], Callable):
+    if len(args) == 1 and callable(args[0]):
         return create_shared_task(**kwargs)(args[0])
     return create_shared_task(*args, **kwargs)

+ 4 - 4
celery/app/base.py

@@ -12,7 +12,7 @@ import os
 import threading
 import warnings
 
-from collections import Callable, defaultdict, deque
+from collections import defaultdict, deque
 from contextlib import contextmanager
 from copy import deepcopy
 from operator import attrgetter
@@ -213,7 +213,7 @@ class Celery(object):
 
             return _create_task_cls
 
-        if len(args) == 1 and isinstance(args[0], Callable):
+        if len(args) == 1 and callable(args[0]):
             return inner_create_task_cls(**opts)(*args)
         if args:
             raise TypeError(
@@ -252,7 +252,7 @@ class Celery(object):
                     task.bind(self)
 
     def add_defaults(self, fun):
-        if not isinstance(fun, Callable):
+        if not callable(fun):
             d, fun = fun, lambda: d
         if self.configured:
             return self.conf.add_defaults(fun())
@@ -290,7 +290,7 @@ class Celery(object):
 
     def _autodiscover_tasks(self, packages, related_name='tasks', **kwargs):
         # argument may be lazy
-        packages = packages() if isinstance(packages, Callable) else packages
+        packages = packages() if callable(packages) else packages
         self.loader.autodiscover_tasks(packages, related_name)
 
     def send_task(self, name, args=None, kwargs=None, countdown=None,

+ 1 - 2
celery/bin/amqp.py

@@ -12,7 +12,6 @@ import sys
 import shlex
 import pprint
 
-from collections import Callable
 from functools import partial
 from itertools import count
 
@@ -99,7 +98,7 @@ class Spec(object):
         """Format the return value of this command in a human-friendly way."""
         if not self.returns:
             return 'ok.' if response is None else response
-        if isinstance(self.returns, Callable):
+        if callable(self.returns):
             return self.returns(response)
         return self.returns.format(response)
 

+ 1 - 3
celery/tests/tasks/test_context.py

@@ -1,8 +1,6 @@
 # -*- coding: utf-8 -*-'
 from __future__ import absolute_import
 
-from collections import Callable
-
 from celery.app.task import Context
 from celery.tests.case import AppCase
 
@@ -15,7 +13,7 @@ def get_context_as_dict(ctx, getter=getattr):
         if attr_name.startswith('_'):
             continue   # Ignore pseudo-private attributes
         attr = getter(ctx, attr_name)
-        if isinstance(attr, Callable):
+        if callable(attr):
             continue   # Ignore methods and other non-trivial types
         defaults[attr_name] = attr
     return defaults

+ 3 - 3
celery/tests/tasks/test_tasks.py

@@ -1,6 +1,5 @@
 from __future__ import absolute_import
 
-from collections import Callable
 from datetime import datetime, timedelta
 
 from kombu import Queue
@@ -267,8 +266,9 @@ class test_tasks(TasksCase):
     def test_regular_task(self):
         self.assertIsInstance(self.mytask, Task)
         self.assertTrue(self.mytask.run())
-        self.assertTrue(isinstance(self.mytask, Callable),
-                        'Task class is callable()')
+        self.assertTrue(
+            callable(self.mytask), 'Task class is callable()',
+        )
         self.assertTrue(self.mytask(), 'Task class runs run() when called')
 
         with self.app.connection_or_acquire() as conn:

+ 1 - 2
celery/utils/dispatch/signal.py

@@ -3,7 +3,6 @@
 from __future__ import absolute_import
 
 import weakref
-from collections import Callable
 from . import saferef
 from celery.five import range
 
@@ -95,7 +94,7 @@ class Signal(object):  # pragma: no cover
 
             return _connect_signal
 
-        if args and isinstance(args[0], Callable):
+        if args and callable(args[0]):
             return _handle_options(*args[1:], **kwargs)(args[0])
         return _handle_options(*args, **kwargs)