pytask-dev / pytask

pytask is a workflow management system that facilitates reproducible data analyses.
https://pytask-dev.readthedocs.io/en/stable
Other
114 stars 10 forks source link

BUG: Return type annotations don't work with repeated tasks #574

Closed hmgaudecker closed 8 months ago

hmgaudecker commented 8 months ago

Title says it. Not sure whether this will only affect PathNodes or others, too.

Code Sample, a copy-pastable example

(apologies for not being self-contained can do next week if helpful)

This works fine:

def task_table_initial_distribution(
    labels: Annotated[
        dict[str, dict[str, str]],
        data[model_name][gender]["labels"],
) -> Annotated[
    str,
    BLD / "tables" / model_name / gender / "initial_states.tex",
]:
    return "some string"

This leads to an error:

for model_name, summary in MODEL_NAMES_TO_NODES.items():
    for gender in GENDERS:

        @task(id=f"{model_name}-{gender}")
        def table_initial_distribution(
            labels: Annotated[
                dict[str, dict[str, str]],
                data[model_name][gender]["labels"],
            ],
        ) -> Annotated[
            str,
            BLD / "tables" / model_name / gender / "initial_states.tex",
        ]:
            return "some string"

namely:


──────────────────────────────────────────────────────────────────────────────────── Task task_initial_distribution.py::table_initial_distribution failed ────────────────────────────────────────────────────────────────────────────────────

TypeError: 'PathNode' can only save 'str' and 'bytes', not <class 'NoneType'>