Skip to content

Commit 192a35f

Browse files
dependabot[bot]tobiasraabepre-commit-ci[bot]
authored
Bump ty from 0.0.18 to 0.0.20 (#809)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tobias Raabe <tobias.raabe@quantilope.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2cc4675 commit 192a35f

5 files changed

Lines changed: 45 additions & 33 deletions

File tree

src/_pytask/cache.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@
1313
from typing import ParamSpec
1414
from typing import Protocol
1515
from typing import TypeVar
16+
from typing import cast
1617

1718
from _pytask._hashlib import hash_value
1819

20+
P = ParamSpec("P")
21+
R = TypeVar("R")
22+
1923
if TYPE_CHECKING:
2024
from collections.abc import Callable
21-
from typing import TypeAlias
2225

2326
from ty_extensions import Intersection
2427

25-
Memoized: TypeAlias = "Intersection[Callable[P, R], HasCache]"
26-
27-
P = ParamSpec("P")
28-
R = TypeVar("R")
29-
3028

3129
class HasCache(Protocol):
3230
"""Protocol for objects that have a cache attribute."""
3331

3432
cache: Cache
3533

3634

35+
if TYPE_CHECKING:
36+
Memoized = Intersection[Callable[P, R], HasCache]
37+
38+
3739
@dataclass
3840
class CacheInfo:
3941
hits: int = 0
@@ -68,9 +70,10 @@ def wrapped(*args: P.args, **kwargs: P.kwargs) -> R:
6870

6971
return value
7072

71-
wrapped.cache = self # ty: ignore[unresolved-attribute]
73+
wrapped_with_cache = cast("Memoized[P, R]", wrapped)
74+
wrapped_with_cache.cache = self
7275

73-
return wrapped
76+
return wrapped_with_cache
7477

7578
def add(self, key: str, value: Any) -> None:
7679
self._cache[key] = value

src/_pytask/collect.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def pytask_collect_task(
352352
)
353353

354354
markers = get_all_marks(obj)
355+
attributes: dict[str, Any]
355356

356357
if isinstance(obj, TaskFunction):
357358
attributes = {
@@ -361,7 +362,11 @@ def pytask_collect_task(
361362
"is_generator": obj.pytask_meta.is_generator,
362363
}
363364
else:
364-
attributes = {"collection_id": None, "after": [], "is_generator": False}
365+
attributes = {
366+
"collection_id": None,
367+
"after": [],
368+
"is_generator": False,
369+
}
365370

366371
unwrapped = unwrap_task_function(obj)
367372
if isinstance(unwrapped, Function):

src/_pytask/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def pytask_configure(pm: PluginManager, raw_config: dict[str, Any]) -> dict[str,
6666
"""Configure pytask."""
6767
# Add all values by default so that many plugins do not need to copy over values.
6868
config = {"pm": pm, "markers": {}} | raw_config
69-
config["markers"] = parse_markers(config["markers"]) # type: ignore[arg-type]
69+
config["markers"] = parse_markers(config["markers"])
7070

7171
pm.hook.pytask_parse_config(config=config)
7272
pm.hook.pytask_post_parse(config=config)

tests/test_collect_command.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import textwrap
66
from dataclasses import dataclass
77
from pathlib import Path
8+
from typing import TYPE_CHECKING
89

910
import pytest
1011

@@ -16,6 +17,9 @@
1617
from pytask import cli
1718
from tests.conftest import enter_directory
1819

20+
if TYPE_CHECKING:
21+
from _pytask.node_protocols import PTaskWithPath
22+
1923

2024
def test_collect_task(runner, tmp_path):
2125
source = """
@@ -315,7 +319,7 @@ def function(depends_on, produces): ...
315319

316320

317321
def test_print_collected_tasks_without_nodes(capsys):
318-
dictionary = {
322+
dictionary: dict[Path, list[PTaskWithPath]] = {
319323
Path("task_path.py"): [
320324
Task(
321325
base_name="function",
@@ -337,7 +341,7 @@ def test_print_collected_tasks_without_nodes(capsys):
337341

338342

339343
def test_print_collected_tasks_with_nodes(capsys):
340-
dictionary = {
344+
dictionary: dict[Path, list[PTaskWithPath]] = {
341345
Path("task_path.py"): [
342346
Task(
343347
base_name="function",
@@ -361,7 +365,7 @@ def test_print_collected_tasks_with_nodes(capsys):
361365

362366
@pytest.mark.parametrize(("show_nodes", "expected_add"), [(False, "src"), (True, "..")])
363367
def test_find_common_ancestor_of_all_nodes(show_nodes, expected_add):
364-
tasks = [
368+
tasks: list[PTaskWithPath] = [
365369
Task(
366370
base_name="function",
367371
path=Path.cwd() / "src" / "task_path.py",

uv.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)