lib: Change Iterable to Collection for truthy checks

Change parameter types from Iterable[str] to Collection[str] wherever
the parameter is tested for emptiness (if not names). This satisfies
the new truthy-iterable mypy rule, since bare Iterable values are
always truthy even when empty.

Affected files:
- Distro.py: install, delete, select, _select, _select_by_name
- rpm.py: query_packages
- suse/Distro.py: _select_by_name
- Cmd.py (secrets): _match_files, _list_template_files, etc.
- DistroContext.py: list_template_files, list_secret_paths, etc.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL and pi.dev 0.81.1
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-07-22 22:29:27 +02:00
commit dcbd4b1c84
5 changed files with 25 additions and 23 deletions

View file

@ -12,6 +12,7 @@ from .log import ERR, INFO, WARNING, log
from .base import InputMode
if TYPE_CHECKING:
from collections.abc import Collection
from typing import Iterable
from .base import Result
@ -359,16 +360,16 @@ class Distro(abc.ABC):
# -- select
@abc.abstractmethod
async def _select_by_name(self, names: Iterable[str]) -> Iterable[Package]:
async def _select_by_name(self, names: Collection[str]) -> Iterable[Package]:
pass
async def _select(self, names: Iterable[str],
async def _select(self, names: Collection[str],
filter: PackageFilter) -> Iterable[Package]:
return [p for p in await self._select_by_name(names) if filter.match(p)]
async def select(
self,
names: Iterable[str] = [],
names: Collection[str] = [],
filter: PackageFilter | None = None
) -> Iterable[Package]:
if not filter:
@ -434,7 +435,7 @@ class Distro(abc.ABC):
if names:
await self._install(names, only_update = only_update)
async def install(self, names: Iterable[str], only_update: bool = False) -> None:
async def install(self, names: Collection[str], only_update: bool = False) -> None:
if not names:
log(WARNING, 'No packages specified for installation')
return
@ -446,7 +447,7 @@ class Distro(abc.ABC):
async def _delete(self, names: Iterable[str]) -> None:
pass
async def delete(self, names: Iterable[str]) -> None:
async def delete(self, names: Collection[str]) -> None:
if not names:
log(WARNING, 'No packages specified for deletion')
return