arq
arq copied to clipboard
Type hints for cron_jobs
The documentation for cron jobs in docs/examples/cron.py use a coroutine as the argument to cron()
, though that function expects coroutine to be a string or something that satisfies the WorkerCoroutine protocol.
Because of this the current example gives an error in with mypy.
> mypy docs/examples/cron.py
docs/examples/cron.py:10: error: Argument 1 to "cron" has incompatible type "Callable[[Any], Coroutine[Any, Any, None]]"; expected "Union[str, WorkerCoroutine]"
The cron function also has a check to verify that the value is a coroutine so specifying a class that matches to WorkerCoroutine doesn't seem to work:
assert asyncio.iscoroutinefunction(coroutine_), f'{coroutine_} is not a coroutine function'
Was the original idea that this should have worked in a different way? Should the type hints in cron be changed to accept either a string or a coroutine?
For now I've just added a comment to ignore type checking for that line in my code.
Been facing the same issue, worked around it by passing it as a string (package_name.function_name
)
@samuelcolvin any reason it doesn't expect a coroutine directly?
Same issue. This cannot be solved simply by passing the function name as a string.
Same issue. This cannot be solved simply by passing the function name as a string.
@FyZzyss works for me like this: https://github.com/akhilnarang/vlrgg-scraper/blob/master/app/cron.py#L143-L147