Closed slaperche-scality closed 5 years ago
I was surprised to see that you can pass normal functions and lambas to the title attribute,but partial functions (functools.partial) aren't accepted:
title
functools.partial
#!/usr/bin/env python # coding: utf-8 import functools def show_cmd(extra, task): return '{}: executing... {}'.format(extra, task.name) def task_lambda_ok(): return { 'actions':['echo lambda'], 'title': lambda task: show_cmd('LAMBDA', task) } def task_partial_ko(): title = functools.partial(show_cmd, extra='PARTIAL') return { 'actions':['echo partial'], 'title': title, }
gives
% doit list ERROR: Task 'partial_ko' attribute 'title' must be {function, None} got:functools.partial(<function show_cmd at 0x7f26847466a8>, extra='PARTIAL') <class 'functools.partial'>
Is that on purpose or is it an oversight?
Seems prevented by https://github.com/pydoit/doit/blob/master/doit/task.py#L156, so it probably could be easily fixed by using collections.abc.Callable instead of types.FunctionType (but maybe I'm missing something).
collections.abc.Callable
types.FunctionType
You are right. Oversight again. Trivial fix as you pointed out..
I was surprised to see that you can pass normal functions and lambas to the
title
attribute,but partial functions (functools.partial
) aren't accepted:gives
Is that on purpose or is it an oversight?
Seems prevented by https://github.com/pydoit/doit/blob/master/doit/task.py#L156, so it probably could be easily fixed by using
collections.abc.Callable
instead oftypes.FunctionType
(but maybe I'm missing something).