Skip to content

Commit 58b49c8

Browse files
authoredSep 20, 2023
Remove deprecation warning for produces. (#421)
1 parent 3a1df52 commit 58b49c8

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed
 

‎docs/source/changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
3838
- {pull}`418` fixes and error and simplifies code in `dag.py`.
3939
- {pull}`420` converts `DeprecationWarning`s to `FutureWarning`s for the deprecated
4040
decorators.
41+
- {pull}`421` removes the deprecation warning when `produces` is used as an magic
42+
function keyword to define products.
4143

4244
## 0.3.2 - 2023-06-07
4345

‎pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ markers = [
8585
"end_to_end: Flag for tests that cover the whole program.",
8686
]
8787
norecursedirs = [".idea", ".tox"]
88-
filterwarnings = ["ignore:'@pytask.mark.*. is deprecated:DeprecationWarning"]
88+
filterwarnings = ["ignore:'@pytask.mark.*. is deprecated:FutureWarning"]
8989

9090

9191
[tool.refurb]

‎src/_pytask/collect_utils.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def task_example(produces: Annotated[..., Product]):
350350
"""
351351

352352

353-
def parse_products_from_task_function( # noqa: C901
353+
def parse_products_from_task_function(
354354
session: Session, path: Path, name: str, obj: Any
355355
) -> dict[str, Any]:
356356
"""Parse products from task function.
@@ -383,10 +383,6 @@ def parse_products_from_task_function( # noqa: C901
383383

384384
# Parse products from task decorated with @task and that uses produces.
385385
if "produces" in kwargs:
386-
if "produces" not in parameters_with_product_annot:
387-
warnings.warn(
388-
_WARNING_PRODUCES_AS_KWARG, category=FutureWarning, stacklevel=1
389-
)
390386
has_produces_argument = True
391387
collected_products = tree_map_with_path(
392388
lambda p, x: _collect_product(

‎src/_pytask/nodes.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ def state(self) -> str | None:
185185
186186
If ``hash`` is a callable, then use this function to calculate a hash.
187187
188-
If ``hash = True``, :func:`hash` is used for all types except strings.
188+
If ``hash = True``, the builtin ``hash()`` function (`link
189+
<https://docs.python.org/3.11/library/functions.html?highlight=hash#hash>`_) is
190+
used for all types except strings.
189191
190192
The hash for strings is calculated using hashlib because ``hash("asd")`` returns
191193
a different value every invocation since the hash of strings is salted with a

‎tests/test_collect.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ def task_example(
406406
def test_deprecation_warning_for_strings_in_depends_on(runner, tmp_path):
407407
source = """
408408
import pytask
409-
from pathlib import Path
410409
411410
@pytask.mark.depends_on("in.txt")
412411
@pytask.mark.produces("out.txt")
@@ -422,6 +421,22 @@ def task_write_text(depends_on, produces):
422421
assert "Using strings to specify a product" in result.output
423422

424423

424+
@pytest.mark.end_to_end()
425+
def test_no_deprecation_warning_for_using_magic_produces(runner, tmp_path):
426+
source = """
427+
import pytask
428+
from pathlib import Path
429+
430+
def task_write_text(depends_on, produces=Path("out.txt")):
431+
produces.touch()
432+
"""
433+
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))
434+
435+
result = runner.invoke(cli, [tmp_path.as_posix()])
436+
assert "FutureWarning" not in result.output
437+
assert "Using 'produces' as an argument name" not in result.output
438+
439+
425440
@pytest.mark.end_to_end()
426441
def test_setting_name_for_path_node_via_annotation(tmp_path):
427442
source = """

0 commit comments

Comments
 (0)