leapp-repository/SOURCES/0042-pylint-enable-use-a-generator.patch
2025-12-01 09:14:24 +00:00

204 lines
12 KiB
Diff

From 215f307eeb1362e420ac08f528f9f11d6c1c974d Mon Sep 17 00:00:00 2001
From: Tomas Fratrik <tfratrik@redhat.com>
Date: Mon, 8 Sep 2025 08:10:13 +0200
Subject: [PATCH 42/55] pylint: enable use-a-generator
Comprehensions inside functions like any(), all(), max(), min(), or sum()
are unnecessary. Enabling this warning enforces using generator expressions
instead of full list/set comprehensions in these cases.
Jira: RHELMISC-16038
---
.pylintrc | 1 -
.../common/actors/checkluks/libraries/checkluks.py | 2 +-
.../actors/checksaphana/tests/test_checksaphana.py | 7 +++++--
.../tests/test_ddddload.py | 2 +-
.../tests/test_persistentnetnamesconfig.py | 2 +-
.../libraries/scandynamiclinkerconfiguration.py | 2 +-
.../tests/test_checksystemdbrokensymlinks.py | 4 ++--
.../tests/test_transitionsystemdservicesstates.py | 6 ++----
.../tests/unit_test_targetuserspacecreator.py | 4 ++--
.../actors/rocecheck/tests/unit_test_rocecheck.py | 10 ++++++++--
10 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/.pylintrc b/.pylintrc
index 4cfc49e0..a82f8818 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -41,7 +41,6 @@ disable=
# new for python3 version of pylint
unnecessary-pass,
raise-missing-from, # no 'raise from' in python 2
- use-a-generator, # cannot be modified because of Python2 support
consider-using-f-string, # sorry, not gonna happen, still have to support py2
logging-format-interpolation
diff --git a/repos/system_upgrade/common/actors/checkluks/libraries/checkluks.py b/repos/system_upgrade/common/actors/checkluks/libraries/checkluks.py
index d52b9e73..84e8e61f 100644
--- a/repos/system_upgrade/common/actors/checkluks/libraries/checkluks.py
+++ b/repos/system_upgrade/common/actors/checkluks/libraries/checkluks.py
@@ -27,7 +27,7 @@ def _formatted_list_output(input_list, sep=FMT_LIST_SEPARATOR):
def _at_least_one_tpm_token(luks_dump):
- return any([token.token_type == "clevis-tpm2" for token in luks_dump.tokens])
+ return any(token.token_type == "clevis-tpm2" for token in luks_dump.tokens)
def _get_ceph_volumes():
diff --git a/repos/system_upgrade/common/actors/checksaphana/tests/test_checksaphana.py b/repos/system_upgrade/common/actors/checksaphana/tests/test_checksaphana.py
index 29e9c930..8ec8d17f 100644
--- a/repos/system_upgrade/common/actors/checksaphana/tests/test_checksaphana.py
+++ b/repos/system_upgrade/common/actors/checksaphana/tests/test_checksaphana.py
@@ -284,7 +284,7 @@ def test_checksaphana_perform_check(monkeypatch):
# Expected 3 reports due to v1names + v2lownames + running
assert len(reports) == 3
# Verifies that all expected title patterns are within the reports and not just coincidentally 3
- assert all([any([pattern(report) for report in reports]) for pattern in EXPECTED_TITLE_PATTERNS.values()])
+ assert all(any(pattern(report) for report in reports) for pattern in EXPECTED_TITLE_PATTERNS.values())
list_clear(reports)
monkeypatch.setattr(checksaphana.api, 'consume', _consume_mock_sap_hana_info(
@@ -294,4 +294,7 @@ def test_checksaphana_perform_check(monkeypatch):
# Expected 2 reports due to v1names + v2lownames
assert len(reports) == 2
# Verifies that all expected title patterns are within the reports and not just coincidentally 2
- assert all([any([EXPECTED_TITLE_PATTERNS[pattern](report) for report in reports]) for pattern in ['v1', 'low']])
+ assert all(
+ any(EXPECTED_TITLE_PATTERNS[pattern](report) for report in reports)
+ for pattern in ['v1', 'low']
+ )
diff --git a/repos/system_upgrade/common/actors/loaddevicedriverdeprecationdata/tests/test_ddddload.py b/repos/system_upgrade/common/actors/loaddevicedriverdeprecationdata/tests/test_ddddload.py
index c3386745..1f3473b6 100644
--- a/repos/system_upgrade/common/actors/loaddevicedriverdeprecationdata/tests/test_ddddload.py
+++ b/repos/system_upgrade/common/actors/loaddevicedriverdeprecationdata/tests/test_ddddload.py
@@ -60,7 +60,7 @@ def test_filtered_load(monkeypatch):
assert produced
assert len(produced[0].entries) == 3
- assert not any([e.device_type == 'unsupported' for e in produced[0].entries])
+ assert not any(e.device_type == 'unsupported' for e in produced[0].entries)
@pytest.mark.parametrize('data', (
diff --git a/repos/system_upgrade/common/actors/persistentnetnamesconfig/tests/test_persistentnetnamesconfig.py b/repos/system_upgrade/common/actors/persistentnetnamesconfig/tests/test_persistentnetnamesconfig.py
index 5ad52c43..ee199ae4 100644
--- a/repos/system_upgrade/common/actors/persistentnetnamesconfig/tests/test_persistentnetnamesconfig.py
+++ b/repos/system_upgrade/common/actors/persistentnetnamesconfig/tests/test_persistentnetnamesconfig.py
@@ -177,7 +177,7 @@ def test_bz_1899455_crash_iface(monkeypatch, adjust_cwd):
for prod_models in [RenamedInterfaces, InitrdIncludes, TargetInitramfsTasks]:
any(isinstance(i, prod_models) for i in persistentnetnamesconfig.api.produce.model_instances)
- assert any(['Some network devices' in x for x in persistentnetnamesconfig.api.current_logger.warnmsg])
+ assert any('Some network devices' in x for x in persistentnetnamesconfig.api.current_logger.warnmsg)
def test_no_network_renaming(monkeypatch):
diff --git a/repos/system_upgrade/common/actors/scandynamiclinkerconfiguration/libraries/scandynamiclinkerconfiguration.py b/repos/system_upgrade/common/actors/scandynamiclinkerconfiguration/libraries/scandynamiclinkerconfiguration.py
index 8d3b473e..73b0c84e 100644
--- a/repos/system_upgrade/common/actors/scandynamiclinkerconfiguration/libraries/scandynamiclinkerconfiguration.py
+++ b/repos/system_upgrade/common/actors/scandynamiclinkerconfiguration/libraries/scandynamiclinkerconfiguration.py
@@ -113,5 +113,5 @@ def scan_dynamic_linker_configuration():
included_configs=included_config_files,
used_variables=used_variables)
- if other_lines or any([config.modified for config in included_config_files]) or used_variables:
+ if other_lines or any(config.modified for config in included_config_files) or used_variables:
api.produce(configuration)
diff --git a/repos/system_upgrade/common/actors/systemd/checksystemdbrokensymlinks/tests/test_checksystemdbrokensymlinks.py b/repos/system_upgrade/common/actors/systemd/checksystemdbrokensymlinks/tests/test_checksystemdbrokensymlinks.py
index bcc33f13..a4c0a657 100644
--- a/repos/system_upgrade/common/actors/systemd/checksystemdbrokensymlinks/tests/test_checksystemdbrokensymlinks.py
+++ b/repos/system_upgrade/common/actors/systemd/checksystemdbrokensymlinks/tests/test_checksystemdbrokensymlinks.py
@@ -20,7 +20,7 @@ def test_report_broken_symlinks(monkeypatch):
checksystemdbrokensymlinks._report_broken_symlinks(symlinks)
assert created_reports.called
- assert all([s in created_reports.report_fields['summary'] for s in symlinks])
+ assert all(s in created_reports.report_fields['summary'] for s in symlinks)
def test_report_enabled_services_broken_symlinks(monkeypatch):
@@ -35,7 +35,7 @@ def test_report_enabled_services_broken_symlinks(monkeypatch):
checksystemdbrokensymlinks._report_enabled_services_broken_symlinks(symlinks)
assert created_reports.called
- assert all([s in created_reports.report_fields['summary'] for s in symlinks])
+ assert all(s in created_reports.report_fields['summary'] for s in symlinks)
class ReportBrokenSymlinks:
diff --git a/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/tests/test_transitionsystemdservicesstates.py b/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/tests/test_transitionsystemdservicesstates.py
index 6964a65b..488b37d4 100644
--- a/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/tests/test_transitionsystemdservicesstates.py
+++ b/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/tests/test_transitionsystemdservicesstates.py
@@ -205,9 +205,7 @@ def test_report_kept_enabled(monkeypatch, tasks, expect_extended_summary):
assert created_reports.called
if expect_extended_summary:
assert extended_summary_str in created_reports.report_fields["summary"]
- assert all(
- [s in created_reports.report_fields["summary"] for s in tasks.to_enable]
- )
+ all(s in created_reports.report_fields['summary'] for s in tasks.to_enable)
else:
assert extended_summary_str not in created_reports.report_fields["summary"]
@@ -238,7 +236,7 @@ def test_report_newly_enabled(monkeypatch):
transitionsystemdservicesstates._report_newly_enabled(newly_enabled)
assert created_reports.called
- assert all([s in created_reports.report_fields["summary"] for s in newly_enabled])
+ assert all(s in created_reports.report_fields["summary"] for s in newly_enabled)
@pytest.mark.parametrize(
diff --git a/repos/system_upgrade/common/actors/targetuserspacecreator/tests/unit_test_targetuserspacecreator.py b/repos/system_upgrade/common/actors/targetuserspacecreator/tests/unit_test_targetuserspacecreator.py
index bb17d89a..0bb64f6f 100644
--- a/repos/system_upgrade/common/actors/targetuserspacecreator/tests/unit_test_targetuserspacecreator.py
+++ b/repos/system_upgrade/common/actors/targetuserspacecreator/tests/unit_test_targetuserspacecreator.py
@@ -1068,7 +1068,7 @@ def test_consume_data(monkeypatch, raised, no_rhsm, testdata):
assert raised[1] in err.value.message
else:
assert userspacegen.api.current_logger.warnmsg
- assert any([raised[1] in x for x in userspacegen.api.current_logger.warnmsg])
+ assert any(raised[1] in x for x in userspacegen.api.current_logger.warnmsg)
@pytest.mark.skip(reason="Currently not implemented in the actor. It's TODO.")
@@ -1390,7 +1390,7 @@ def test__get_files_owned_by_rpms_recursive(monkeypatch):
assert sorted(owned[0:4]) == sorted(out)
def has_dbgmsg(substr):
- return any([substr in log for log in logger.dbgmsg])
+ return any(substr in log for log in logger.dbgmsg)
# test a few
assert has_dbgmsg(
diff --git a/repos/system_upgrade/el8toel9/actors/rocecheck/tests/unit_test_rocecheck.py b/repos/system_upgrade/el8toel9/actors/rocecheck/tests/unit_test_rocecheck.py
index a36cc8ed..b5511d17 100644
--- a/repos/system_upgrade/el8toel9/actors/rocecheck/tests/unit_test_rocecheck.py
+++ b/repos/system_upgrade/el8toel9/actors/rocecheck/tests/unit_test_rocecheck.py
@@ -91,7 +91,10 @@ def test_roce_old_rhel(monkeypatch, msgs, version):
monkeypatch.setattr(reporting, "create_report", create_report_mocked())
rocecheck.process()
assert reporting.create_report.called
- assert any(['version of RHEL' in report['title'] for report in reporting.create_report.reports])
+ assert any(
+ 'version of RHEL' in report['title']
+ for report in reporting.create_report.reports
+ )
# NOTE: what about the situation when net.naming-scheme is configured multiple times???
@@ -113,4 +116,7 @@ def test_roce_wrong_configuration(monkeypatch, msgs, version):
monkeypatch.setattr(reporting, "create_report", create_report_mocked())
rocecheck.process()
assert reporting.create_report.called
- assert any(['RoCE configuration' in report['title'] for report in reporting.create_report.reports])
+ assert any(
+ 'RoCE configuration' in report['title']
+ for report in reporting.create_report.reports
+ )
--
2.51.1