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

Add type annotations to doit #420

Open
mathbunnyru opened this issue Mar 19, 2022 · 4 comments
Open

Add type annotations to doit #420

mathbunnyru opened this issue Mar 19, 2022 · 4 comments

Comments

@mathbunnyru
Copy link

mathbunnyru commented Mar 19, 2022

Right now every task looks more-or-less like this:

def task_hello():
    def python_hello(targets):
        with open(targets[0], "a") as output:
            output.write("Python says Hello World!!!\n")

    return {
        'actions': [python_hello],
        'targets': ["hello.txt"],
    }

It would be so nice if we actually had a type-annotated class Task with actions and targets fields.
Right now, every Task is basically dict.
I think, it was a great decision back in the days, but right now we have dataclass, typing module and they work so great for modern code.

Having type annotations in python makes programming much easier:

  • if someone has a typo in the name of some field / function, mypy (python static linter) will catch that
  • all the IDEs give good suggestions, when using typed classes
  • reduce the amount of documentation needed to start using doit
  • the internal code will benefit from using typing as well (for the same reasons)

Unfortunately, adding type annotations to an existing project is not the easiest and the most funny thing to do, but it has lots of benefits.

Fund with Polar
@schettino72
Copy link
Member

yes. I plan to add mypy annotations.

I was thinking about adding a dataclass to be used as an alternative to plain metadata in dictionary for IDE folks.
Could you submit a patch for this?

There are other alternatives for task definition: see #35.
I am also working on one alternative with integration with click...

@schettino72
Copy link
Member

By the way, you know you can get quick documentation on command line with

$ doit help task

@mathbunnyru
Copy link
Author

yes. I plan to add mypy annotations.

I was thinking about adding a dataclass to be used as an alternative to plain metadata in dictionary for IDE folks. Could you submit a patch for this?

There are other alternatives for task definition: see #35. I am also working on one alternative with integration with click...

Yes, dataclasses are great 👍
I think I will be a bit busy for the next couple of months :(
But, if I have some time, I will try to take a closer look at this project (I've only started using it yesterday).

@weakish
Copy link

weakish commented Sep 14, 2022

An alternative to dataclass is TypedDict.

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

No branches or pull requests

3 participants