pydoit / doit

CLI task management & automation tool
http://pydoit.org
MIT License
1.87k stars 175 forks source link

Cannot use functools.partial as title #286

Closed slaperche-scality closed 5 years ago

slaperche-scality commented 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:

#!/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).

schettino72 commented 5 years ago

Is that on purpose or is it an oversight?

You are right. Oversight again. Trivial fix as you pointed out..