Skip to content

Commit

Permalink
Allow class methods to define tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
georgepsarakis authored and Omer Katz committed Apr 9, 2017
1 parent 4f6c3b5 commit 8c4e6dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion celery/utils/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ def head_from_fun(fun, bound=False, debug=False):
# in pure-Python. Instead we use exec to create a new function
# with an empty body, meaning it has the same performance as
# as just calling a function.
if not inspect.isfunction(fun) and hasattr(fun, '__call__'):
is_function = inspect.isfunction(fun)
is_callable = hasattr(fun, '__call__')
is_method = inspect.ismethod(fun)

if not is_function and is_callable and not is_method:
name, fun = fun.__class__.__name__, fun.__call__
else:
name = fun.__name__
Expand Down
12 changes: 12 additions & 0 deletions t/unit/utils/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,18 @@ def test_from_fun_forced_kwargs(self):
g(a=1, b=2)
g(a=1, b=2, c=3)

def test_classmethod(self):
class A(object):
@classmethod
def f(cls, x):
return x

fun = head_from_fun(A.f, bound=False)
assert fun(A, 1) == 1

fun = head_from_fun(A.f, bound=True)
assert fun(1) == 1


class test_fun_takes_argument:

Expand Down

0 comments on commit 8c4e6dd

Please sign in to comment.