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.
mainbranch 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.
Problem description
When I do this example, my type checker complains about the type of the provided hash function.
Type annotation from current master:
pytask/src/_pytask/nodes.py
Line 238 in f18df8f
I think
boolas 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 tostr()), or a more defined one likeCallable[[Any], int | str | bytes]as these are common returns of hash functions.