Skip to content

Commit 7b6f184

Browse files
authored
Fix when multiple product annotations are used. (#448)
1 parent 907a0b9 commit 7b6f184

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

docs/source/changes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
55
releases are available on [PyPI](https://pypi.org/project/pytask) and
66
[Anaconda.org](https://anaconda.org/conda-forge/pytask).
77

8-
## 0.4.1 - 2023-10-08
8+
## 0.4.1 - 2023-10-xx
99

1010
- {pull}`443` ensures that `PythonNode.name` is always unique by only handling it
1111
internally.
1212
- {pull}`444` moves all content of `setup.cfg` to `pyproject.toml`.
13+
- {pull}`447` fixes handling multiple product annotations of a task.
1314

1415
## 0.4.0 - 2023-10-07
1516

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies:
3434
- pytest-cov
3535
- pytest-xdist
3636
- tabulate
37-
- tox-conda
37+
- tox
3838

3939
# Documentation
4040
- furo

src/_pytask/collect_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ def parse_products_from_task_function(
425425
out = {"produces": collected_products}
426426

427427
if parameters_with_product_annot:
428-
has_annotation = True
429-
428+
out = {}
430429
for parameter_name in parameters_with_product_annot:
430+
has_annotation = True
431431
if (
432432
parameter_name not in kwargs
433433
and parameter_name not in parameters_with_node_annot
@@ -465,7 +465,7 @@ def parse_products_from_task_function(
465465
),
466466
value,
467467
)
468-
out = {parameter_name: collected_products}
468+
out[parameter_name] = collected_products
469469

470470
if "return" in parameters_with_node_annot:
471471
has_return = True

tests/test_execute.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,3 +771,27 @@ def create_file(text: Annotated[int, node_text]) -> Annotated[str, node_file]:
771771
def test_pass_non_task_to_functional_api_that_are_ignored():
772772
session = pytask.build(tasks=None)
773773
assert len(session.tasks) == 0
774+
775+
776+
@pytest.mark.end_to_end()
777+
def test_multiple_product_annotations(runner, tmp_path):
778+
source = """
779+
from pytask import Product
780+
from typing_extensions import Annotated
781+
from pathlib import Path
782+
783+
def task_first(
784+
first: Annotated[Path, Product] = Path("first.txt"),
785+
second: Annotated[Path, Product] = Path("second.txt")
786+
):
787+
first.write_text("first")
788+
second.write_text("second")
789+
790+
def task_second(
791+
first: Path = Path("first.txt"), second: Path = Path("second.txt")
792+
):
793+
pass
794+
"""
795+
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
796+
result = runner.invoke(cli, [tmp_path.as_posix()])
797+
assert result.exit_code == ExitCode.OK

0 commit comments

Comments
 (0)