procrastinate
procrastinate copied to clipboard
Complete/fix mypy integration
trafficstars
This is a 2-fold ticket:
- Without a py.typed, our type annotations cannot be used by projects using procrastinate, and it's quite sad. Let's add a py.typed (see https://www.python.org/dev/peps/pep-0561/ )
- Mypy doesn't like our metaprogramming trick @async.add_sync_api and frankly, I understand it makes its job harder. Let's help it by implementing a mypy plugin. We can take direct inspiration from https://github.com/strawberry-graphql/strawberry/blob/4d11e2d26cf3f8f1453c95106606acede85125ac/strawberry/ext/mypy_plugin.py and https://github.com/strawberry-graphql/strawberry/tree/4d11e2d26cf3f8f1453c95106606acede85125ac#type-checking (doc: https://mypy.readthedocs.io/en/latest/extending_mypy.html )
If this ticket is succesful, then from a new python project using mypy, installing procrastinate from PyPI, on the following lines:
app = procrastinate.App(...)
app.run_worker(["hello"]) # should pass mypy
app.run_worker("hello") # should fail mypy
So, we're using add_sync_api less and less in our external API, so this doesn't make as much sense as it used to.
I wonder if we could just provide type stubs somewhere...
We're using pyright instead of mypy now, and we've removed most of the metaprogramming.