refactor: use itertools instead of sum for combining iterables

This commit is contained in:
arcanis committed 2026-11-20 12:06:56 +02:00
1 parent b28c156e78
commit 239149f2b4
7 files changed
+19 -9

No files matched your search

@@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import argparse import argparse
import itertools
from collections.abc import Callable from collections.abc import Callable
@@ -56,9 +57,9 @@ class Status(Handler):
service_status = client.status_get() service_status = client.status_get()
StatusPrinter(service_status.status)(verbose=args.info) StatusPrinter(service_status.status)(verbose=args.info)
if args.package: if args.package:
packages: list[tuple[Package, BuildStatus]] = sum( packages: list[tuple[Package, BuildStatus]] = list(
(client.package_get(base) for base in args.package), itertools.chain.from_iterable(client.package_get(base) for base in args.package)
start=[]) )
else: else:
packages = client.package_get(None) packages = client.package_get(None)
@@ -19,6 +19,7 @@
# #
import argparse import argparse
import copy import copy
import itertools
from typing import Any from typing import Any
@@ -97,7 +98,7 @@ class Validate(Handler):
# create trigger loader instance # create trigger loader instance
loader = TriggerLoader() loader = TriggerLoader()
triggers = loader.selected_triggers(configuration) + loader.known_triggers(configuration) triggers = itertools.chain(loader.selected_triggers(configuration), loader.known_triggers(configuration))
for trigger in set(triggers): for trigger in set(triggers):
try: try:
@@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import argparse import argparse
import itertools
import re import re
import sys import sys
@@ -99,7 +100,7 @@ class Versions(Handler):
keys.extend(portion) keys.extend(portion)
portion = { portion = {
key key
for key in sum((list(dependencies_by_key(key)) for key in portion), start=[]) for key in itertools.chain.from_iterable(dependencies_by_key(key) for key in portion)
if key not in keys if key not in keys
} }
@@ -17,6 +17,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import itertools
from collections.abc import Iterable from collections.abc import Iterable
from ahriman.core.build_tools.package_version import PackageVersion from ahriman.core.build_tools.package_version import PackageVersion
@@ -126,7 +128,7 @@ class UpdateHandler(PackageInfo, Cleaner):
if not dependencies.paths: if not dependencies.paths:
continue # skip check if no package dependencies found continue # skip check if no package dependencies found
required_packages = {dep for dep_packages in dependencies.paths.values() for dep in dep_packages} required_packages = set(itertools.chain.from_iterable(dependencies.paths.values()))
filesystem = extract_files(required_packages) filesystem = extract_files(required_packages)
for path, packages in dependencies.paths.items(): for path, packages in dependencies.paths.items():
+2 -1
View File
@@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import argparse import argparse
import itertools
import uuid import uuid
from collections.abc import Callable, Iterable from collections.abc import Callable, Iterable
@@ -117,7 +118,7 @@ class Spawn(Thread, LazyLogging):
continue # skip null values continue # skip null values
flag = f"--{argument}" flag = f"--{argument}"
if isinstance(value, list): if isinstance(value, list):
arguments.extend(list(sum(((flag, v) for v in value), ()))) arguments.extend(itertools.chain.from_iterable((flag, v) for v in value))
elif value: elif value:
arguments.extend([flag, value]) arguments.extend([flag, value])
else: else:
+3 -1
View File
@@ -17,6 +17,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import itertools
from collections.abc import Callable, Iterable from collections.abc import Callable, Iterable
from typing import Any, ClassVar, Self from typing import Any, ClassVar, Self
@@ -100,7 +102,7 @@ class Result:
Returns: Returns:
list[Package]: list of packages with success result list[Package]: list of packages with success result
""" """
return list(self._added.values()) + list(self._updated.values()) return list(itertools.chain(self._added.values(), self._updated.values()))
def add_added(self, package: Package) -> None: def add_added(self, package: Package) -> None:
""" """
@@ -17,6 +17,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import itertools
from collections.abc import Callable from collections.abc import Callable
from pathlib import Path from pathlib import Path
@@ -117,7 +119,7 @@ class KeyringGenerator(PkgbuildGenerator):
source_path(Path): destination of the file content source_path(Path): destination of the file content
""" """
with source_path.open("w", encoding="utf8") as source_file: with source_path.open("w", encoding="utf8") as source_file:
for key in sorted(set(self.trusted + self.packagers + self.revoked)): for key in sorted(set(itertools.chain(self.trusted, self.packagers, self.revoked))):
public_key = self.sign.key_export(key) public_key = self.sign.key_export(key)
source_file.write(public_key) source_file.write(public_key)
source_file.write("\n") source_file.write("\n")