Skip to content

Commit b195827

Browse files
committed
Replace Sequence with Collection in typing
1 parent 7ae78d2 commit b195827

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

66
## [Unreleased]
7+
### Fixed
8+
- Use `Collection` instead of `Sequence` in typing to support, e.g., dicts.
79

810
## [1.0.15] - 2024-12-28
911
### Added

src/rra_tools/cli_tools/options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import Callable, Sequence
1+
from collections.abc import Callable, Collection
22
from pathlib import Path
33
from typing import Any, ParamSpec, TypeVar
44

@@ -13,7 +13,7 @@
1313
RUN_ALL = "ALL"
1414

1515

16-
def convert_choice(value: str, choices: Sequence[str]) -> list[str]:
16+
def convert_choice(value: str, choices: Collection[str]) -> list[str]:
1717
"""Convert a choice to a list of choices, handling the special 'All' choice.
1818
1919
Parameters
@@ -35,7 +35,7 @@ def convert_choice(value: str, choices: Sequence[str]) -> list[str]:
3535

3636
def process_choices(
3737
allow_all: bool, # noqa: FBT001
38-
choices: Sequence[str] | None,
38+
choices: Collection[str] | None,
3939
) -> tuple[click.ParamType, str | None, bool]:
4040
"""Support function for creating options with choices.
4141
@@ -93,7 +93,7 @@ def with_choice(
9393
short_name: str | None = None,
9494
*,
9595
allow_all: bool = True,
96-
choices: Sequence[str] | None = None,
96+
choices: Collection[str] | None = None,
9797
convert: bool | None = None,
9898
**kwargs: Any,
9999
) -> ClickOption[_P, _T]:

src/rra_tools/jobmon.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22
import uuid
3-
from collections.abc import Callable, Sequence
3+
from collections.abc import Callable, Collection
44
from pathlib import Path
55
from typing import Any
66

@@ -43,8 +43,8 @@ def get_jobmon_tool(workflow_name: str): # type: ignore[no-untyped-def]
4343

4444

4545
def _process_args(
46-
args: dict[str, Sequence[Any] | Any] | None,
47-
) -> tuple[dict[str, Sequence[Any]], str]:
46+
args: dict[str, Collection[Any] | Any] | None,
47+
) -> tuple[dict[str, Collection[Any]], str]:
4848
"""Process arguments for a task.
4949
5050
Parameters
@@ -54,7 +54,7 @@ def _process_args(
5454
5555
Returns
5656
-------
57-
tuple[dict[str, Sequence[Any]], str]
57+
tuple[dict[str, Collection[Any]], str]
5858
The names of all non-flag and non-count arguments and the string
5959
representation of the arguments.
6060
"""
@@ -80,8 +80,8 @@ def build_parallel_task_graph( # type: ignore[no-untyped-def] # noqa: PLR0913
8080
task_name: str,
8181
task_resources: dict[str, str | int],
8282
*,
83-
node_args: dict[str, Sequence[Any] | None] | None = None,
84-
flat_node_args: tuple[tuple[str, ...], Sequence[tuple[Any, ...]]] | None = None,
83+
node_args: dict[str, Collection[Any] | None] | None = None,
84+
flat_node_args: tuple[tuple[str, ...], Collection[tuple[Any, ...]]] | None = None,
8585
task_args: dict[str, Any] | None = None,
8686
op_args: dict[str, Any] | None = None,
8787
max_attempts: int | None = None,
@@ -138,7 +138,7 @@ def build_parallel_task_graph( # type: ignore[no-untyped-def] # noqa: PLR0913
138138
tuple([arg.replace("-", "_") for arg in flat_node_args[0]]),
139139
flat_node_args[1],
140140
)
141-
clean_node_args: dict[str, Sequence[Any]] = {k: [] for k in flat_node_args[0]}
141+
clean_node_args: dict[str, Collection[Any]] = {k: [] for k in flat_node_args[0]}
142142
else:
143143
clean_node_args, node_arg_string = _process_args(node_args)
144144
clean_task_args, task_arg_string = _process_args(task_args)
@@ -225,8 +225,8 @@ def run_parallel( # noqa: PLR0913
225225
task_name: str,
226226
task_resources: dict[str, str | int],
227227
*,
228-
node_args: dict[str, Sequence[Any] | None] | None = None,
229-
flat_node_args: tuple[tuple[str, ...], Sequence[tuple[Any, ...]]] | None = None,
228+
node_args: dict[str, Collection[Any] | None] | None = None,
229+
flat_node_args: tuple[tuple[str, ...], Collection[tuple[Any, ...]]] | None = None,
230230
task_args: dict[str, Any] | None = None,
231231
op_args: dict[str, Any] | None = None,
232232
concurrency_limit: int = 10000,

src/rra_tools/parallel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from __future__ import annotations
1313

14-
from collections.abc import Callable, Sequence
14+
from collections.abc import Callable, Collection
1515
from multiprocessing import Pool as StdLibPool
1616
from typing import Any, TypeVar
1717

@@ -28,7 +28,7 @@
2828

2929
def run_parallel(
3030
runner: Callable[[T], T2],
31-
arg_list: Sequence[T],
31+
arg_list: Collection[T],
3232
*,
3333
num_cores: int = 1,
3434
progress_bar: bool = False,

0 commit comments

Comments
 (0)