Does anyone else in the community use type-hints t...
# prefect-community
Does anyone else in the community use type-hints to track data-dependencies in a Flow? Creating tasks with the
decorator works well for me, but the class-based API confuses my IDE. For example, my IDE thinks the class-based result should be type `Task`:
Copy code
from prefect import Flow, Task, task

def func_task() -> str:
    return ""

class ClassTask(Task):
    def run(self) -> str:
        return ""

class_task = ClassTask()

with Flow("test_type_hints") as flow:
    func_result: str = func_task()
    class_result: str = class_task()  # Expected type 'str', got 'Task' instead
Hi @Maxwell Dylla - your type-checking is evaluating correctly but I can see where the confusion is. It boils down to type-checking happening at script runtime, when the instantiation of that task is correctly returning an instance of the class; what you're expecting is the runtime context resolved with
, which would return the type
that you're expecting from the task's run method.
@nicholas I'm really interested in how the type hints could interact with mypy. It would be a significant quality-of-life improvement for developing/debugging flows if I could type-check data-dependencies between tasks before running/registering flows.
(It doesn't work currently, even with the decorated-tasks, but would be neat)
@Maxwell Dylla - I can see how that would be useful! I'm not very familiar with mypy but I'm sure others would also benefit from strong typing; would you mind opening a feature request on the Prefect Core repo describing what you'd like to see? That'll let the Core team and others chime in on what sort of effort that would require.
Absolutely - thanks, nicholas!