Skip to content

Commit

Permalink
Replace Sequence with Collection in typing
Browse files Browse the repository at this point in the history
  • Loading branch information
collijk committed Dec 30, 2024
1 parent 7ae78d2 commit b195827
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
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).

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

## [1.0.15] - 2024-12-28
### Added
Expand Down
8 changes: 4 additions & 4 deletions src/rra_tools/cli_tools/options.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections.abc import Callable, Sequence
from collections.abc import Callable, Collection
from pathlib import Path
from typing import Any, ParamSpec, TypeVar

Expand All @@ -13,7 +13,7 @@
RUN_ALL = "ALL"


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

def process_choices(
allow_all: bool, # noqa: FBT001
choices: Sequence[str] | None,
choices: Collection[str] | None,
) -> tuple[click.ParamType, str | None, bool]:
"""Support function for creating options with choices.
Expand Down Expand Up @@ -93,7 +93,7 @@ def with_choice(
short_name: str | None = None,
*,
allow_all: bool = True,
choices: Sequence[str] | None = None,
choices: Collection[str] | None = None,
convert: bool | None = None,
**kwargs: Any,
) -> ClickOption[_P, _T]:
Expand Down
18 changes: 9 additions & 9 deletions src/rra_tools/jobmon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import uuid
from collections.abc import Callable, Sequence
from collections.abc import Callable, Collection
from pathlib import Path
from typing import Any

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


def _process_args(
args: dict[str, Sequence[Any] | Any] | None,
) -> tuple[dict[str, Sequence[Any]], str]:
args: dict[str, Collection[Any] | Any] | None,
) -> tuple[dict[str, Collection[Any]], str]:
"""Process arguments for a task.
Parameters
Expand All @@ -54,7 +54,7 @@ def _process_args(
Returns
-------
tuple[dict[str, Sequence[Any]], str]
tuple[dict[str, Collection[Any]], str]
The names of all non-flag and non-count arguments and the string
representation of the arguments.
"""
Expand All @@ -80,8 +80,8 @@ def build_parallel_task_graph( # type: ignore[no-untyped-def] # noqa: PLR0913
task_name: str,
task_resources: dict[str, str | int],
*,
node_args: dict[str, Sequence[Any] | None] | None = None,
flat_node_args: tuple[tuple[str, ...], Sequence[tuple[Any, ...]]] | None = None,
node_args: dict[str, Collection[Any] | None] | None = None,
flat_node_args: tuple[tuple[str, ...], Collection[tuple[Any, ...]]] | None = None,
task_args: dict[str, Any] | None = None,
op_args: dict[str, Any] | None = None,
max_attempts: int | None = None,
Expand Down Expand Up @@ -138,7 +138,7 @@ def build_parallel_task_graph( # type: ignore[no-untyped-def] # noqa: PLR0913
tuple([arg.replace("-", "_") for arg in flat_node_args[0]]),
flat_node_args[1],
)
clean_node_args: dict[str, Sequence[Any]] = {k: [] for k in flat_node_args[0]}
clean_node_args: dict[str, Collection[Any]] = {k: [] for k in flat_node_args[0]}
else:
clean_node_args, node_arg_string = _process_args(node_args)
clean_task_args, task_arg_string = _process_args(task_args)
Expand Down Expand Up @@ -225,8 +225,8 @@ def run_parallel( # noqa: PLR0913
task_name: str,
task_resources: dict[str, str | int],
*,
node_args: dict[str, Sequence[Any] | None] | None = None,
flat_node_args: tuple[tuple[str, ...], Sequence[tuple[Any, ...]]] | None = None,
node_args: dict[str, Collection[Any] | None] | None = None,
flat_node_args: tuple[tuple[str, ...], Collection[tuple[Any, ...]]] | None = None,
task_args: dict[str, Any] | None = None,
op_args: dict[str, Any] | None = None,
concurrency_limit: int = 10000,
Expand Down
4 changes: 2 additions & 2 deletions src/rra_tools/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from __future__ import annotations

from collections.abc import Callable, Sequence
from collections.abc import Callable, Collection
from multiprocessing import Pool as StdLibPool
from typing import Any, TypeVar

Expand All @@ -28,7 +28,7 @@

def run_parallel(
runner: Callable[[T], T2],
arg_list: Sequence[T],
arg_list: Collection[T],
*,
num_cores: int = 1,
progress_bar: bool = False,
Expand Down

0 comments on commit b195827

Please sign in to comment.