-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Using static type checking as qa on a Flow library #3191
Comments
Update: It won't be possible to support this until PEP 612 and changes to mypy go live python/mypy#8645 |
@dyllamt, those type signatures aren't 100% correct - the output of calling a task is another task, the annotations you've provided above tell mypy that the In #3346 I fixed the |
I think that's an elegant solution. When I was approaching the problem, I was just thinking about a narrow scope of looking at types within the context of flow execution. Parameterization seems like a good tack. In my mind, a |
This is a bit tricky, since prefect doesn't disambiguate between tasks that have been called (and represent a delayed result) and tasks that haven't been called and should be treated more like functions. The first really only needs the result parameter, while the second would need both. In my experience I rarely see code passing around uncalled tasks as higher-order functions, so parametrizing on the call signature feels less important to me than on the call result (without higher-order functions, mypy can statically check the caller type signature on the task itself, which is already exposed). That said, perhaps the extra complication would be worth it, and would future-proof us against situations where that becomes more common. |
Thinking it over, I feel comfortable parameterizing on just the return type. You're right - I never use higher-order functions with tasks. Generally, I have a module of pure functions, and then at the last minute in a Flow module, I'll convert to tasks:
I guess I would have to stop using the task decorator this way, since we need to hint that the task accepts |
We built support for tracking call signature annotations early on (e.g., https://github.com/PrefectHQ/prefect/blob/master/src/prefect/core/task.py#L744) and could probably leverage this to do some static validation independently of |
This issue is stale because it has been open 30 days with no activity. To keep this issue open remove stale label or comment. |
This issue was closed because it has been stale for 14 days with no activity. If this issue is important or you have more to add feel free to re-open it. |
Current behavior
As a user developing
Flow
s, I struggle with debugging flows, since each of the tasks represents delayed execution. Running a flow is the most complete test, but since flows can change the state of external systems, it would be helpful to have some qa that my flow is set-up correctly before running/registering. This is especially impactful in the situation where I have a flow library and want to implement this qa as part of a CI pipeline.Proposed behavior
For flows with
Task
s that have data dependencies between them, I could qa on the types passed between different tasks. Right now, tasks are typed to hint at the types encountered when the flow is registered. Imagine a scenario, where the types hinted at the task execution result (the result of the delayed execution). You could run mypy and ensure that the dependencies between flows have sensible types (plus your IDE will be more helpful)Example
The text was updated successfully, but these errors were encountered: