Skip to content

Remove deprecation warning for produces. #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
- {pull}`418` fixes and error and simplifies code in `dag.py`.
- {pull}`420` converts `DeprecationWarning`s to `FutureWarning`s for the deprecated
decorators.
- {pull}`421` removes the deprecation warning when `produces` is used as an magic
function keyword to define products.

## 0.3.2 - 2023-06-07

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ markers = [
"end_to_end: Flag for tests that cover the whole program.",
]
norecursedirs = [".idea", ".tox"]
filterwarnings = ["ignore:'@pytask.mark.*. is deprecated:DeprecationWarning"]
filterwarnings = ["ignore:'@pytask.mark.*. is deprecated:FutureWarning"]


[tool.refurb]
Expand Down
6 changes: 1 addition & 5 deletions src/_pytask/collect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def task_example(produces: Annotated[..., Product]):
"""


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

# Parse products from task decorated with @task and that uses produces.
if "produces" in kwargs:
if "produces" not in parameters_with_product_annot:
warnings.warn(
_WARNING_PRODUCES_AS_KWARG, category=FutureWarning, stacklevel=1
)
has_produces_argument = True
collected_products = tree_map_with_path(
lambda p, x: _collect_product(
Expand Down
4 changes: 3 additions & 1 deletion src/_pytask/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def state(self) -> str | None:

If ``hash`` is a callable, then use this function to calculate a hash.

If ``hash = True``, :func:`hash` is used for all types except strings.
If ``hash = True``, the builtin ``hash()`` function (`link
<https://docs.python.org/3.11/library/functions.html?highlight=hash#hash>`_) is
used for all types except strings.

The hash for strings is calculated using hashlib because ``hash("asd")`` returns
a different value every invocation since the hash of strings is salted with a
Expand Down
17 changes: 16 additions & 1 deletion tests/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ def task_example(
def test_deprecation_warning_for_strings_in_depends_on(runner, tmp_path):
source = """
import pytask
from pathlib import Path

@pytask.mark.depends_on("in.txt")
@pytask.mark.produces("out.txt")
Expand All @@ -422,6 +421,22 @@ def task_write_text(depends_on, produces):
assert "Using strings to specify a product" in result.output


@pytest.mark.end_to_end()
def test_no_deprecation_warning_for_using_magic_produces(runner, tmp_path):
source = """
import pytask
from pathlib import Path

def task_write_text(depends_on, produces=Path("out.txt")):
produces.touch()
"""
tmp_path.joinpath("task_module.py").write_text(textwrap.dedent(source))

result = runner.invoke(cli, [tmp_path.as_posix()])
assert "FutureWarning" not in result.output
assert "Using 'produces' as an argument name" not in result.output


@pytest.mark.end_to_end()
def test_setting_name_for_path_node_via_annotation(tmp_path):
source = """
Expand Down