Skip to content

Commit

Permalink
Removing last references to task_method (celery#4645)
Browse files Browse the repository at this point in the history
* Removing last references to task_method from app/task

* Removing last references to task_method from dispatch/signal

* Removing test

* Removing test
  • Loading branch information
auvipy authored Apr 7, 2018
1 parent e3b973d commit c96287f
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 53 deletions.
16 changes: 1 addition & 15 deletions celery/app/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
# We take __repr__ very seriously around here ;)
R_BOUND_TASK = '<class {0.__name__} of {app}{flags}>'
R_UNBOUND_TASK = '<unbound {0.__name__}{flags}>'
R_SELF_TASK = '<@task {0.name} bound to other {0.__self__}>'
R_INSTANCE = '<@task: {0.name} of {app}{flags}>'

#: Here for backwards compatibility as tasks no longer use a custom meta-class.
Expand Down Expand Up @@ -161,9 +160,6 @@ class Task(object):
#: Request class used, or the qualified name of one.
Request = 'celery.worker.request:Request'

#: This is the instance bound to if the task is a method of a class.
__self__ = None

#: The application instance associated with this task class.
_app = None

Expand Down Expand Up @@ -377,9 +373,6 @@ def __call__(self, *args, **kwargs):
_task_stack.push(self)
self.push_request(args=args, kwargs=kwargs)
try:
# add self if this is a bound task
if self.__self__ is not None:
return self.run(self.__self__, *args, **kwargs)
return self.run(*args, **kwargs)
finally:
self.pop_request()
Expand Down Expand Up @@ -525,10 +518,6 @@ def apply_async(self, args=None, kwargs=None, task_id=None, producer=None,
with denied_join_result():
return self.apply(args, kwargs, task_id=task_id or uuid(),
link=link, link_error=link_error, **options)
# add 'self' if this is a "task_method".
if self.__self__ is not None:
args = args if isinstance(args, tuple) else tuple(args or ())
args = (self.__self__,) + args

if self.__v2_compat__:
shadow = shadow or self.shadow_name(self(), args, kwargs, options)
Expand Down Expand Up @@ -717,9 +706,6 @@ def apply(self, args=None, kwargs=None,

app = self._get_app()
args = args or ()
# add 'self' if this is a bound method.
if self.__self__ is not None:
args = (self.__self__,) + tuple(args)
kwargs = kwargs or {}
task_id = task_id or uuid()
retries = retries or 0
Expand Down Expand Up @@ -983,7 +969,7 @@ def pop_request(self):

def __repr__(self):
"""``repr(task)``."""
return _reprtask(self, R_SELF_TASK if self.__self__ else R_INSTANCE)
return _reprtask(self, R_INSTANCE)

def _get_request(self):
"""Get current request object."""
Expand Down
11 changes: 1 addition & 10 deletions celery/utils/dispatch/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _make_id(target): # pragma: no cover
# see Issue #2475
return target
if hasattr(target, '__func__'):
return (id(target.__self__), id(target.__func__))
return id(target.__func__)
return id(target)


Expand Down Expand Up @@ -182,15 +182,6 @@ def _connect_signal(self, receiver, sender, weak, dispatch_uid):
if weak:
ref = weakref.ref
receiver_object = receiver
# Check for bound methods
try:
receiver.__self__
receiver.__func__
except AttributeError:
pass
else:
ref = WeakMethod
receiver_object = receiver.__self__
if PY3:
receiver = ref(receiver)
weakref.finalize(receiver_object, self._remove_receiver)
Expand Down
18 changes: 0 additions & 18 deletions t/unit/app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,24 +494,6 @@ def _inner(*args, **kwargs):
i.annotate()
i.annotate()

def test_apply_async_has__self__(self):
@self.app.task(__self__='hello', shared=False)
def aawsX(x, y):
pass

with pytest.raises(TypeError):
aawsX.apply_async(())
with pytest.raises(TypeError):
aawsX.apply_async((2,))

with patch('celery.app.amqp.AMQP.create_task_message') as create:
with patch('celery.app.amqp.AMQP.send_task_message') as send:
create.return_value = Mock(), Mock(), Mock(), Mock()
aawsX.apply_async((4, 5))
args = create.call_args[0][2]
assert args, ('hello', 4 == 5)
send.assert_called()

def test_apply_async_adds_children(self):
from celery._state import _task_stack

Expand Down
10 changes: 0 additions & 10 deletions t/unit/tasks/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,6 @@ def test_repr_v2_compat(self):
self.mytask.__v2_compat__ = True
assert 'v2 compatible' in repr(self.mytask)

def test_apply_with_self(self):

@self.app.task(__self__=42, shared=False)
def tawself(self):
return self

assert tawself.apply().get() == 42

assert tawself() == 42

def test_context_get(self):
self.mytask.push_request()
try:
Expand Down

0 comments on commit c96287f

Please sign in to comment.