@@ -555,9 +555,7 @@ def test_return_with_path_annotation_as_return(runner, tmp_path):
555
555
from typing_extensions import Annotated
556
556
from pytask import PathNode
557
557
558
- path = Path(__file__).parent.joinpath("file.txt")
559
-
560
- def task_example() -> Annotated[str, path]:
558
+ def task_example() -> Annotated[str, Path("file.txt")]:
561
559
return "Hello, World!"
562
560
"""
563
561
tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
@@ -647,3 +645,24 @@ def task_example() -> Annotated[int, node]:
647
645
648
646
data = pickle .loads (tmp_path .joinpath ("data.pkl" ).read_bytes ()) # noqa: S301
649
647
assert data == 1
648
+
649
+
650
+ @pytest .mark .end_to_end ()
651
+ def test_error_when_return_pytree_mismatch (runner , tmp_path ):
652
+ source = """
653
+ from pathlib import Path
654
+ from typing import Any
655
+ from typing_extensions import Annotated
656
+ from pytask import PathNode
657
+
658
+ node1 = PathNode.from_path(Path(__file__).parent.joinpath("file1.txt"))
659
+ node2 = PathNode.from_path(Path(__file__).parent.joinpath("file2.txt"))
660
+
661
+ def task_example() -> Annotated[str, (node1, node2)]:
662
+ return "Hello,"
663
+ """
664
+ tmp_path .joinpath ("task_module.py" ).write_text (textwrap .dedent (source ))
665
+ result = runner .invoke (cli , [tmp_path .as_posix ()])
666
+ assert result .exit_code == ExitCode .FAILED
667
+ assert "Function return: PyTreeSpec(*, NoneIsLeaf)" in result .output
668
+ assert "Return annotation: PyTreeSpec((*, *), NoneIsLeaf)" in result .output
0 commit comments