Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task decorator is wrongly typed #946

Open
kasium opened this issue May 16, 2023 · 3 comments
Open

task decorator is wrongly typed #946

kasium opened this issue May 16, 2023 · 3 comments

Comments

@kasium
Copy link

kasium commented May 16, 2023

from invoke.tasks import task
from invoke.collection import Collection

@task
def foo(ctx):
    pass

ns = Collection()
ns.add_task(foo)

leads to an mypy error:

error: Argument 1 to "add_task" of "Collection" has incompatible type "Callable[..., Any]"; expected "Task[Any]"  [arg-type]
    ns.add_task(foo)
@kasium kasium changed the title task decorator task decorator is wrongly typed May 16, 2023
@4sushi
Copy link

4sushi commented Jun 22, 2023

Your code works well on the last version of invoke:

In [1]: from invoke.tasks import task
   ...: from invoke.collection import Collection
   ...: 
   ...: @task
   ...: def foo(ctx):
   ...:     pass
   ...: 
   ...: ns = Collection()
   ...: ns.add_task(foo)

In [2]: ns
Out[2]: <Collection None: foo>

In [3]: ns.tasks
Out[3]: {'foo': <Task 'foo'>}

Which version of invoke are you using? Maybe you may consider to upgrade it:

pip install invoke --upgrade
python -m invoke --version
# Your version need to be >= 2.1.3

Also, based on the documentation, you may simplify your imports:

from invoke import task
from invoke import Collection

@kasium
Copy link
Author

kasium commented Jun 22, 2023

@4sushi the code works but mypy complains as I said

@kuwv
Copy link
Contributor

kuwv commented Jul 10, 2023

#956

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants