Skip to content

BUG: Type Annotations in PythonNode Wrong #654

Description

@axtimhaus
  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pytask.
  • (optional) I have confirmed this bug exists on the main branch of pytask.

Code Sample, a copy-pastable example

This is the example from the docs https://pytask-dev.readthedocs.io/en/stable/how_to_guides/hashing_inputs_of_tasks.html.

import json
from pathlib import Path
from typing import Annotated
from typing import Any

from deepdiff import DeepHash
from pytask import Product
from pytask import PythonNode


def calculate_hash(x: Any) -> str:
    return DeepHash(x)[x]


node = PythonNode(value={"a": 1, "b": 2}, hash=calculate_hash)


def task_example(
    data: Annotated[dict[str, int], node],
    path: Annotated[Path, Product] = Path("file.txt"),
) -> None:
    path.write_text(json.dumps(data))

Problem description

When I do this example, my type checker complains about the type of the provided hash function.

Type annotation from current master:

hash: bool | Callable[[Any], bool] = False

I think bool as return type of the callable makes no sense here.
Running the code works perfectly fine, just the checker complaining.

Expected Output

By looking into the source Callable[[Any], Any] would work (because the result is passed to str()), or a more defined one like Callable[[Any], int | str | bytes] as these are common returns of hash functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions