From 32feac5348bd6e54d0a96ffafa208f91fcaa5087 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 Mar 2026 16:19:08 +0000 Subject: [PATCH 1/4] Bump ty from 0.0.18 to 0.0.20 Bumps [ty](https://github.com/astral-sh/ty) from 0.0.18 to 0.0.20. - [Release notes](https://github.com/astral-sh/ty/releases) - [Changelog](https://github.com/astral-sh/ty/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ty/compare/0.0.18...0.0.20) --- updated-dependencies: - dependency-name: ty dependency-version: 0.0.20 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- uv.lock | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/uv.lock b/uv.lock index 400fafa4..8962e531 100644 --- a/uv.lock +++ b/uv.lock @@ -4028,26 +4028,26 @@ wheels = [ [[package]] name = "ty" -version = "0.0.18" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/74/15/9682700d8d60fdca7afa4febc83a2354b29cdcd56e66e19c92b521db3b39/ty-0.0.18.tar.gz", hash = "sha256:04ab7c3db5dcbcdac6ce62e48940d3a0124f377c05499d3f3e004e264ae94b83", size = 5214774, upload-time = "2026-02-20T21:51:31.173Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/ae/d8/920460d4c22ea68fcdeb0b2fb53ea2aeb9c6d7875bde9278d84f2ac767b6/ty-0.0.18-py3-none-linux_armv6l.whl", hash = "sha256:4e5e91b0a79857316ef893c5068afc4b9872f9d257627d9bc8ac4d2715750d88", size = 10280825, upload-time = "2026-02-20T21:51:25.03Z" }, - { url = "https://files.pythonhosted.org/packages/83/56/62587de582d3d20d78fcdddd0594a73822ac5a399a12ef512085eb7a4de6/ty-0.0.18-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:ee0e578b3f8416e2d5416da9553b78fd33857868aa1384cb7fefeceee5ff102d", size = 10118324, upload-time = "2026-02-20T21:51:22.27Z" }, - { url = "https://files.pythonhosted.org/packages/2f/2d/dbdace8d432a0755a7417f659bfd5b8a4261938ecbdfd7b42f4c454f5aa9/ty-0.0.18-py3-none-macosx_11_0_arm64.whl", hash = "sha256:3f7a0487d36b939546a91d141f7fc3dbea32fab4982f618d5b04dc9d5b6da21e", size = 9605861, upload-time = "2026-02-20T21:51:16.066Z" }, - { url = "https://files.pythonhosted.org/packages/6b/d9/de11c0280f778d5fc571393aada7fe9b8bc1dd6a738f2e2c45702b8b3150/ty-0.0.18-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d5e2fa8d45f57ca487a470e4bf66319c09b561150e98ae2a6b1a97ef04c1a4eb", size = 10092701, upload-time = "2026-02-20T21:51:26.862Z" }, - { url = "https://files.pythonhosted.org/packages/0f/94/068d4d591d791041732171e7b63c37a54494b2e7d28e88d2167eaa9ad875/ty-0.0.18-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d75652e9e937f7044b1aca16091193e7ef11dac1c7ec952b7fb8292b7ba1f5f2", size = 10109203, upload-time = "2026-02-20T21:51:11.59Z" }, - { url = "https://files.pythonhosted.org/packages/34/e4/526a4aa56dc0ca2569aaa16880a1ab105c3b416dd70e87e25a05688999f3/ty-0.0.18-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:563c868edceb8f6ddd5e91113c17d3676b028f0ed380bdb3829b06d9beb90e58", size = 10614200, upload-time = "2026-02-20T21:51:20.298Z" }, - { url = "https://files.pythonhosted.org/packages/fd/3d/b68ab20a34122a395880922587fbfc3adf090d22e0fb546d4d20fe8c2621/ty-0.0.18-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:502e2a1f948bec563a0454fc25b074bf5cf041744adba8794d024277e151d3b0", size = 11153232, upload-time = "2026-02-20T21:51:14.121Z" }, - { url = "https://files.pythonhosted.org/packages/68/ea/678243c042343fcda7e6af36036c18676c355878dcdcd517639586d2cf9e/ty-0.0.18-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:cc881dea97021a3aa29134a476937fd8054775c4177d01b94db27fcfb7aab65b", size = 10832934, upload-time = "2026-02-20T21:51:32.92Z" }, - { url = "https://files.pythonhosted.org/packages/d8/bd/7f8d647cef8b7b346c0163230a37e903c7461c7248574840b977045c77df/ty-0.0.18-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:421fcc3bc64cab56f48edb863c7c1c43649ec4d78ff71a1acb5366ad723b6021", size = 10700888, upload-time = "2026-02-20T21:51:09.673Z" }, - { url = "https://files.pythonhosted.org/packages/6e/06/cb3620dc48c5d335ba7876edfef636b2f4498eff4a262ff90033b9e88408/ty-0.0.18-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:0fe5038a7136a0e638a2fb1ad06e3d3c4045314c6ba165c9c303b9aeb4623d6c", size = 10078965, upload-time = "2026-02-20T21:51:07.678Z" }, - { url = "https://files.pythonhosted.org/packages/60/27/c77a5a84533fa3b685d592de7b4b108eb1f38851c40fac4e79cc56ec7350/ty-0.0.18-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d123600a52372677613a719bbb780adeb9b68f47fb5f25acb09171de390e0035", size = 10134659, upload-time = "2026-02-20T21:51:18.311Z" }, - { url = "https://files.pythonhosted.org/packages/43/6e/60af6b88c73469e628ba5253a296da6984e0aa746206f3034c31f1a04ed1/ty-0.0.18-py3-none-musllinux_1_2_i686.whl", hash = "sha256:bb4bc11d32a1bf96a829bf6b9696545a30a196ac77bbc07cc8d3dfee35e03723", size = 10297494, upload-time = "2026-02-20T21:51:39.631Z" }, - { url = "https://files.pythonhosted.org/packages/33/90/612dc0b68224c723faed6adac2bd3f930a750685db76dfe17e6b9e534a83/ty-0.0.18-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:dda2efbf374ba4cd704053d04e32f2f784e85c2ddc2400006b0f96f5f7e4b667", size = 10791944, upload-time = "2026-02-20T21:51:37.13Z" }, - { url = "https://files.pythonhosted.org/packages/0d/da/f4ada0fd08a9e4138fe3fd2bcd3797753593f423f19b1634a814b9b2a401/ty-0.0.18-py3-none-win32.whl", hash = "sha256:c5768607c94977dacddc2f459ace6a11a408a0f57888dd59abb62d28d4fee4f7", size = 9677964, upload-time = "2026-02-20T21:51:42.039Z" }, - { url = "https://files.pythonhosted.org/packages/5e/fa/090ed9746e5c59fc26d8f5f96dc8441825171f1f47752f1778dad690b08b/ty-0.0.18-py3-none-win_amd64.whl", hash = "sha256:b78d0fa1103d36fc2fce92f2092adace52a74654ab7884d54cdaec8eb5016a4d", size = 10636576, upload-time = "2026-02-20T21:51:29.159Z" }, - { url = "https://files.pythonhosted.org/packages/92/4f/5dd60904c8105cda4d0be34d3a446c180933c76b84ae0742e58f02133713/ty-0.0.18-py3-none-win_arm64.whl", hash = "sha256:01770c3c82137c6b216aa3251478f0b197e181054ee92243772de553d3586398", size = 10095449, upload-time = "2026-02-20T21:51:34.914Z" }, +version = "0.0.21" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ee/20/2ba8fd9493c89c41dfe9dbb73bc70a28b28028463bc0d2897ba8be36230a/ty-0.0.21.tar.gz", hash = "sha256:a4c2ba5d67d64df8fcdefd8b280ac1149d24a73dbda82fa953a0dff9d21400ed", size = 5297967, upload-time = "2026-03-06T01:57:13.809Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/36/70/edf38bb37517531681d1c37f5df64744e5ad02673c02eb48447eae4bea08/ty-0.0.21-py3-none-linux_armv6l.whl", hash = "sha256:7bdf2f572378de78e1f388d24691c89db51b7caf07cf90f2bfcc1d6b18b70a76", size = 10299222, upload-time = "2026-03-06T01:57:16.64Z" }, + { url = "https://files.pythonhosted.org/packages/72/62/0047b0bd19afeefbc7286f20a5f78a2aa39f92b4d89853f0d7185ab89edc/ty-0.0.21-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:7e9613994610431ab8625025bd2880dbcb77c5c9fabdd21134cda12d840a529d", size = 10130513, upload-time = "2026-03-06T01:57:29.93Z" }, + { url = "https://files.pythonhosted.org/packages/a2/20/0b93a9e91aaed23155780258cdfdb4726ef68b6985378ac069bc427291a0/ty-0.0.21-py3-none-macosx_11_0_arm64.whl", hash = "sha256:56d3b198b64dd0a19b2b66e257deaed2ecea568e722ae5352f3c6fb62027f89d", size = 9605425, upload-time = "2026-03-06T01:57:27.115Z" }, + { url = "https://files.pythonhosted.org/packages/ea/fd/9945e2fa2996a1287b1e1d7ce050e97e1f420233b271e770934bfa0880a0/ty-0.0.21-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d23d2c34f7a77d974bb08f0860ef700addc8a683d81a0319f71c08f87506cfd0", size = 10108298, upload-time = "2026-03-06T01:57:35.429Z" }, + { url = "https://files.pythonhosted.org/packages/52/e7/4ec52fcb15f3200826c9f048472c062549a05b0d1ef0b51f32d527b513c4/ty-0.0.21-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:56b01fd2519637a4ca88344f61c96225f540c98ff18bca321d4eaa7bb0f7aa2f", size = 10121556, upload-time = "2026-03-06T01:57:03.242Z" }, + { url = "https://files.pythonhosted.org/packages/ee/c0/ad457be2a8abea0f25549598bd098554540ced66229488daa0d558dad3c8/ty-0.0.21-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e9de7e11c63c6afc40f3e9ba716374add171aee7fabc70b5146a510705c6d41b", size = 10603264, upload-time = "2026-03-06T01:56:52.134Z" }, + { url = "https://files.pythonhosted.org/packages/f8/5b/2ecc7a2175243a4bcb72f5298ae41feabbb93b764bb0dc45722f3752c2c2/ty-0.0.21-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:62f7f5b235c4f7876db305c36997aea07b7af29b1a068f373d0e2547e25f32ff", size = 11196428, upload-time = "2026-03-06T01:57:32.94Z" }, + { url = "https://files.pythonhosted.org/packages/37/f5/aff507d6a901f328ef96a298032b0c11aaaf950a146ed7dd3b5bf2cd3acf/ty-0.0.21-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ee8399f7c453a425291e6688efe430cfae7ab0ac4ffd50eba9f872bf878b54f6", size = 10866355, upload-time = "2026-03-06T01:56:57.831Z" }, + { url = "https://files.pythonhosted.org/packages/be/30/822bbcb92d55b65989aa7ed06d9585f28ade9c9447369194ed4b0fb3b5b9/ty-0.0.21-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:210e7568c9f886c4d01308d751949ee714ad7ad9d7d928d2ba90d329dd880367", size = 10738177, upload-time = "2026-03-06T01:57:11.256Z" }, + { url = "https://files.pythonhosted.org/packages/57/cc/46e7991b6469e93ac2c7e533a028983e402485580150ac864c56352a3a82/ty-0.0.21-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:53508e345b11569f78b21ba8e2b4e61df38a9754947fb3cd9f2ef574367338fb", size = 10079158, upload-time = "2026-03-06T01:57:00.516Z" }, + { url = "https://files.pythonhosted.org/packages/15/c2/0bbdadfbd008240f8f1a87dc877433cb3884436097926107ccf06e618199/ty-0.0.21-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:553e43571f4a35604c36cfd07d8b61a5eb7a714e3c67f8c4ff2cf674fefbaef9", size = 10150535, upload-time = "2026-03-06T01:57:08.815Z" }, + { url = "https://files.pythonhosted.org/packages/c5/b5/2dbdb7b57b5362200ef0a39738ebd31331726328336def0143ac097ee59d/ty-0.0.21-py3-none-musllinux_1_2_i686.whl", hash = "sha256:666f6822e3b9200abfa7e95eb0ddd576460adb8d66b550c0ad2c70abc84a2048", size = 10319803, upload-time = "2026-03-06T01:57:19.106Z" }, + { url = "https://files.pythonhosted.org/packages/72/84/70e52c0b7abc7c2086f9876ef454a73b161d3125315536d8d7e911c94ca4/ty-0.0.21-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a0854d008347ce4a5fb351af132f660a390ab2a1163444d075251d43e6f74b9b", size = 10826239, upload-time = "2026-03-06T01:57:21.727Z" }, + { url = "https://files.pythonhosted.org/packages/a1/8a/1f72480fd013bbc6cd1929002abbbcde9a0b08ead6a15154de9d7f7fa37e/ty-0.0.21-py3-none-win32.whl", hash = "sha256:bef3ab4c7b966bcc276a8ac6c11b63ba222d21355b48d471ea782c4104eee4e0", size = 9693196, upload-time = "2026-03-06T01:57:24.126Z" }, + { url = "https://files.pythonhosted.org/packages/8d/f8/1104808b875c26c640e536945753a78562d606bef4e241d9dbf3d92477f6/ty-0.0.21-py3-none-win_amd64.whl", hash = "sha256:a709d576e5bea84b745d43058d8b9cd4f27f74a0b24acb4b0cbb7d3d41e0d050", size = 10668660, upload-time = "2026-03-06T01:56:55.06Z" }, + { url = "https://files.pythonhosted.org/packages/1b/b8/25e0adc404bbf986977657b25318991f93097b49f8aea640d93c0b0db68e/ty-0.0.21-py3-none-win_arm64.whl", hash = "sha256:f72047996598ac20553fb7e21ba5741e3c82dee4e9eadf10d954551a5fe09391", size = 10104161, upload-time = "2026-03-06T01:57:06.072Z" }, ] [[package]] From 93b727d71245d5b4c13c743743bc57784bca9ce0 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Mon, 9 Mar 2026 17:03:21 +0100 Subject: [PATCH 2/4] Fix ty 0.0.20 compatibility issues --- src/_pytask/cache.py | 7 +------ src/_pytask/collect.py | 7 ++++++- src/_pytask/config.py | 2 +- tests/test_cache.py | 16 ++++++++++------ tests/test_collect_command.py | 7 ++++--- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/_pytask/cache.py b/src/_pytask/cache.py index c3e851fc..5e1d90c1 100644 --- a/src/_pytask/cache.py +++ b/src/_pytask/cache.py @@ -18,11 +18,6 @@ if TYPE_CHECKING: from collections.abc import Callable - from typing import TypeAlias - - from ty_extensions import Intersection - - Memoized: TypeAlias = "Intersection[Callable[P, R], HasCache]" P = ParamSpec("P") R = TypeVar("R") @@ -46,7 +41,7 @@ class Cache: _sentinel: Any = field(default_factory=object) cache_info: CacheInfo = field(default_factory=CacheInfo) - def memoize(self, func: Callable[P, R]) -> Memoized[P, R]: + def memoize(self, func: Callable[P, R]) -> Callable[P, R]: func_module = getattr(func, "__module__", "") func_name = getattr(func, "__name__", "") prefix = f"{func_module}.{func_name}:" diff --git a/src/_pytask/collect.py b/src/_pytask/collect.py index ee038d30..13753e30 100644 --- a/src/_pytask/collect.py +++ b/src/_pytask/collect.py @@ -352,6 +352,7 @@ def pytask_collect_task( ) markers = get_all_marks(obj) + attributes: dict[str, Any] if isinstance(obj, TaskFunction): attributes = { @@ -361,7 +362,11 @@ def pytask_collect_task( "is_generator": obj.pytask_meta.is_generator, } else: - attributes = {"collection_id": None, "after": [], "is_generator": False} + attributes = { + "collection_id": None, + "after": [], + "is_generator": False, + } unwrapped = unwrap_task_function(obj) if isinstance(unwrapped, Function): diff --git a/src/_pytask/config.py b/src/_pytask/config.py index 5ec826ac..ac8fc8f1 100644 --- a/src/_pytask/config.py +++ b/src/_pytask/config.py @@ -66,7 +66,7 @@ def pytask_configure(pm: PluginManager, raw_config: dict[str, Any]) -> dict[str, """Configure pytask.""" # Add all values by default so that many plugins do not need to copy over values. config = {"pm": pm, "markers": {}} | raw_config - config["markers"] = parse_markers(config["markers"]) # type: ignore[arg-type] + config["markers"] = parse_markers(config["markers"]) pm.hook.pytask_parse_config(config=config) pm.hook.pytask_post_parse(config=config) diff --git a/tests/test_cache.py b/tests/test_cache.py index 335623fc..7f5e2322 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,8 +1,10 @@ from __future__ import annotations import inspect +from typing import cast from _pytask.cache import Cache +from _pytask.cache import HasCache from _pytask.cache import _make_memoize_key @@ -13,20 +15,22 @@ def test_cache(): def func(a, b): return a + b - assert func.cache.cache_info.hits == 0 - assert func.cache.cache_info.misses == 0 + cached_func = cast("HasCache", func) + + assert cached_func.cache.cache_info.hits == 0 + assert cached_func.cache.cache_info.misses == 0 value = func(1, b=2) assert value == 3 - assert func.cache.cache_info.hits == 0 - assert func.cache.cache_info.misses == 1 + assert cached_func.cache.cache_info.hits == 0 + assert cached_func.cache.cache_info.misses == 1 assert next(i for i in cache._cache.values()) == 3 value = func(1, b=2) assert value == 3 - assert func.cache.cache_info.hits == 1 - assert func.cache.cache_info.misses == 1 + assert cached_func.cache.cache_info.hits == 1 + assert cached_func.cache.cache_info.misses == 1 def test_cache_add(): diff --git a/tests/test_collect_command.py b/tests/test_collect_command.py index debfb610..ed33512d 100644 --- a/tests/test_collect_command.py +++ b/tests/test_collect_command.py @@ -10,6 +10,7 @@ from _pytask.collect_command import _find_common_ancestor_of_all_nodes from _pytask.collect_command import _print_collected_tasks +from _pytask.node_protocols import PTaskWithPath from pytask import ExitCode from pytask import PathNode from pytask import Task @@ -315,7 +316,7 @@ def function(depends_on, produces): ... def test_print_collected_tasks_without_nodes(capsys): - dictionary = { + dictionary: dict[Path, list[PTaskWithPath]] = { Path("task_path.py"): [ Task( base_name="function", @@ -337,7 +338,7 @@ def test_print_collected_tasks_without_nodes(capsys): def test_print_collected_tasks_with_nodes(capsys): - dictionary = { + dictionary: dict[Path, list[PTaskWithPath]] = { Path("task_path.py"): [ Task( base_name="function", @@ -361,7 +362,7 @@ def test_print_collected_tasks_with_nodes(capsys): @pytest.mark.parametrize(("show_nodes", "expected_add"), [(False, "src"), (True, "..")]) def test_find_common_ancestor_of_all_nodes(show_nodes, expected_add): - tasks = [ + tasks: list[PTaskWithPath] = [ Task( base_name="function", path=Path.cwd() / "src" / "task_path.py", From 3f63125fe80c2b65edde66001585de2efa646811 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Mar 2026 16:03:37 +0000 Subject: [PATCH 3/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_collect_command.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_collect_command.py b/tests/test_collect_command.py index ed33512d..532d6b97 100644 --- a/tests/test_collect_command.py +++ b/tests/test_collect_command.py @@ -5,18 +5,21 @@ import textwrap from dataclasses import dataclass from pathlib import Path +from typing import TYPE_CHECKING import pytest from _pytask.collect_command import _find_common_ancestor_of_all_nodes from _pytask.collect_command import _print_collected_tasks -from _pytask.node_protocols import PTaskWithPath from pytask import ExitCode from pytask import PathNode from pytask import Task from pytask import cli from tests.conftest import enter_directory +if TYPE_CHECKING: + from _pytask.node_protocols import PTaskWithPath + def test_collect_task(runner, tmp_path): source = """ From 8e2c6a4325081018109f2cee30b703299ff031cc Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Mon, 9 Mar 2026 17:07:45 +0100 Subject: [PATCH 4/4] Restore intersection type for memoized callables --- src/_pytask/cache.py | 18 +++++++++++++----- tests/test_cache.py | 16 ++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/_pytask/cache.py b/src/_pytask/cache.py index 5e1d90c1..068fb590 100644 --- a/src/_pytask/cache.py +++ b/src/_pytask/cache.py @@ -13,14 +13,17 @@ from typing import ParamSpec from typing import Protocol from typing import TypeVar +from typing import cast from _pytask._hashlib import hash_value +P = ParamSpec("P") +R = TypeVar("R") + if TYPE_CHECKING: from collections.abc import Callable -P = ParamSpec("P") -R = TypeVar("R") + from ty_extensions import Intersection class HasCache(Protocol): @@ -29,6 +32,10 @@ class HasCache(Protocol): cache: Cache +if TYPE_CHECKING: + Memoized = Intersection[Callable[P, R], HasCache] + + @dataclass class CacheInfo: hits: int = 0 @@ -41,7 +48,7 @@ class Cache: _sentinel: Any = field(default_factory=object) cache_info: CacheInfo = field(default_factory=CacheInfo) - def memoize(self, func: Callable[P, R]) -> Callable[P, R]: + def memoize(self, func: Callable[P, R]) -> Memoized[P, R]: func_module = getattr(func, "__module__", "") func_name = getattr(func, "__name__", "") prefix = f"{func_module}.{func_name}:" @@ -63,9 +70,10 @@ def wrapped(*args: P.args, **kwargs: P.kwargs) -> R: return value - wrapped.cache = self # ty: ignore[unresolved-attribute] + wrapped_with_cache = cast("Memoized[P, R]", wrapped) + wrapped_with_cache.cache = self - return wrapped + return wrapped_with_cache def add(self, key: str, value: Any) -> None: self._cache[key] = value diff --git a/tests/test_cache.py b/tests/test_cache.py index 7f5e2322..335623fc 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -1,10 +1,8 @@ from __future__ import annotations import inspect -from typing import cast from _pytask.cache import Cache -from _pytask.cache import HasCache from _pytask.cache import _make_memoize_key @@ -15,22 +13,20 @@ def test_cache(): def func(a, b): return a + b - cached_func = cast("HasCache", func) - - assert cached_func.cache.cache_info.hits == 0 - assert cached_func.cache.cache_info.misses == 0 + assert func.cache.cache_info.hits == 0 + assert func.cache.cache_info.misses == 0 value = func(1, b=2) assert value == 3 - assert cached_func.cache.cache_info.hits == 0 - assert cached_func.cache.cache_info.misses == 1 + assert func.cache.cache_info.hits == 0 + assert func.cache.cache_info.misses == 1 assert next(i for i in cache._cache.values()) == 3 value = func(1, b=2) assert value == 3 - assert cached_func.cache.cache_info.hits == 1 - assert cached_func.cache.cache_info.misses == 1 + assert func.cache.cache_info.hits == 1 + assert func.cache.cache_info.misses == 1 def test_cache_add():