You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by hu...@apache.org on 2024/04/15 11:14:39 UTC
(airflow) branch main updated: Activate ruff B007 to detect unused variables in the loop (#38309)
This is an automated email from the ASF dual-hosted git repository.
husseinawala pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 95a136e7fd Activate ruff B007 to detect unused variables in the loop (#38309)
95a136e7fd is described below
commit 95a136e7fda4ada07174020c37bf373e1c3c7d88
Author: Hussein Awala <hu...@awala.fr>
AuthorDate: Mon Apr 15 13:14:31 2024 +0200
Activate ruff B007 to detect unused variables in the loop (#38309)
* Activate ruff B007 to detect unused variables in the loop
* fix a bug in the change
* Delete scripts/ci/pre_commit/pre_commit_insert_extras.py
---
dev/breeze/src/airflow_breeze/commands/release_management_commands.py | 2 +-
dev/breeze/src/airflow_breeze/commands/sbom_commands.py | 2 +-
dev/example_dags/update_example_dags_paths.py | 2 +-
dev/stats/get_important_pr_candidates.py | 2 +-
docs/conf.py | 4 ++--
pyproject.toml | 1 +
scripts/ci/pre_commit/check_init_in_tests.py | 2 +-
scripts/ci/pre_commit/insert_extras.py | 2 +-
scripts/ci/pre_commit/update_example_dags_paths.py | 2 +-
scripts/ci/pre_commit/vendor_k8s_json_schema.py | 2 +-
scripts/ci/testing/summarize_junit_failures.py | 2 +-
tests/cli/commands/test_internal_api_command.py | 2 +-
tests/cli/commands/test_webserver_command.py | 2 +-
tests/integration/executors/test_celery_executor.py | 2 +-
tests/integration/providers/apache/kafka/operators/test_consume.py | 2 +-
.../integration/providers/apache/kafka/triggers/test_await_message.py | 2 +-
tests/jobs/test_backfill_job.py | 2 +-
tests/models/test_serialized_dag.py | 2 +-
tests/models/test_taskinstance.py | 2 +-
tests/providers/fab/auth_manager/test_security.py | 2 +-
tests/serialization/test_serialized_objects.py | 2 +-
.../system/providers/cncf/kubernetes/example_kubernetes_decorator.py | 2 +-
tests/test_utils/perf/perf_kit/memory.py | 2 +-
tests/utils/test_log_handlers.py | 2 +-
24 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
index 0fae67e485..ba2834375a 100644
--- a/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
+++ b/dev/breeze/src/airflow_breeze/commands/release_management_commands.py
@@ -1478,7 +1478,7 @@ def run_publish_docs_in_parallel(
]
# Iterate over the results and collect success and skipped entries
- for index, result in enumerate(results):
+ for result in results:
return_code, message = result.get()
if return_code == 0:
success_entries.append(message)
diff --git a/dev/breeze/src/airflow_breeze/commands/sbom_commands.py b/dev/breeze/src/airflow_breeze/commands/sbom_commands.py
index c75db28d6b..458298564e 100644
--- a/dev/breeze/src/airflow_breeze/commands/sbom_commands.py
+++ b/dev/breeze/src/airflow_breeze/commands/sbom_commands.py
@@ -320,7 +320,7 @@ def update_sbom_information(
_generate_index(destination_dir, None, airflow_v)
elif package_filter == "apache-airflow-providers":
for (
- node_name,
+ _,
provider_id,
provider_version,
provider_version_documentation_directory,
diff --git a/dev/example_dags/update_example_dags_paths.py b/dev/example_dags/update_example_dags_paths.py
index 265a9e98e9..2104721d1b 100755
--- a/dev/example_dags/update_example_dags_paths.py
+++ b/dev/example_dags/update_example_dags_paths.py
@@ -93,7 +93,7 @@ def replace_match(file: str, line: str, provider: str, version: str) -> str | No
def find_matches(_file: Path, provider: str, version: str):
lines = _file.read_text().splitlines(keepends=True)
new_lines = []
- for index, line in enumerate(lines):
+ for line in lines:
new_line = replace_match(str(_file), line, provider, version)
if new_line:
new_lines.append(new_line)
diff --git a/dev/stats/get_important_pr_candidates.py b/dev/stats/get_important_pr_candidates.py
index 6256df4a3c..8a02fa9704 100755
--- a/dev/stats/get_important_pr_candidates.py
+++ b/dev/stats/get_important_pr_candidates.py
@@ -350,7 +350,7 @@ def main(
if load:
console.print("Loading PRs from cache and recalculating scores.")
selected_prs = pickle.load(load, encoding="bytes")
- for issue_num, pr in enumerate(selected_prs, 1):
+ for pr in selected_prs:
console.print(
f"[green]Loading PR: #{pr.pull_request.number} `{pr.pull_request.title}`.[/]"
f" Score: {pr.score}."
diff --git a/docs/conf.py b/docs/conf.py
index 00e698803c..951b5ba082 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -454,7 +454,7 @@ def get_configs_and_deprecations(
# the config has been templated, not before
# e.g. {{dag_id}} in default_config.cfg -> {dag_id} in airflow.cfg, and what we want in docs
keys_to_format = ["default", "example"]
- for conf_name, conf_section in configs.items():
+ for conf_section in configs.values():
for option_name, option in list(conf_section["options"].items()):
for key in keys_to_format:
if option[key] and "{{" in option[key]:
@@ -464,7 +464,7 @@ def get_configs_and_deprecations(
del conf_section["options"][option_name]
# Sort options, config and deprecated options for JINJA variables to display
- for section_name, config in configs.items():
+ for config in configs.values():
config["options"] = {k: v for k, v in sorted(config["options"].items())}
configs = {k: v for k, v in sorted(configs.items())}
for section in deprecated_options:
diff --git a/pyproject.toml b/pyproject.toml
index 1b505517d2..cd27952820 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -291,6 +291,7 @@ extend-select = [
"S101", # Checks use `assert` outside the test cases, test cases should be added into the exclusions
"B004", # Checks for use of hasattr(x, "__call__") and replaces it with callable(x)
"B006", # Checks for uses of mutable objects as function argument defaults.
+ "B007", # Checks for unused variables in the loop
"B017", # Checks for pytest.raises context managers that catch Exception or BaseException.
"B019", # Use of functools.lru_cache or functools.cache on methods can lead to memory leaks
"B028", # No explicit stacklevel keyword argument found
diff --git a/scripts/ci/pre_commit/check_init_in_tests.py b/scripts/ci/pre_commit/check_init_in_tests.py
index 92cc7802cf..a9c6dee237 100755
--- a/scripts/ci/pre_commit/check_init_in_tests.py
+++ b/scripts/ci/pre_commit/check_init_in_tests.py
@@ -40,7 +40,7 @@ errors: list[str] = []
added = False
if __name__ == "__main__":
- for dirname, sub_dirs, files in os.walk(ROOT_DIR / "tests"):
+ for dirname, sub_dirs, _ in os.walk(ROOT_DIR / "tests"):
dir = Path(dirname)
sub_dirs[:] = [subdir for subdir in sub_dirs if subdir not in {"__pycache__", "test_logs"}]
for sub_dir in sub_dirs:
diff --git a/scripts/ci/pre_commit/insert_extras.py b/scripts/ci/pre_commit/insert_extras.py
index 16faeaad2c..5eeddd17d6 100755
--- a/scripts/ci/pre_commit/insert_extras.py
+++ b/scripts/ci/pre_commit/insert_extras.py
@@ -82,7 +82,7 @@ def process_documentation_files() -> bool:
for file, file_format, add_comment in FILES_TO_UPDATE:
if not file.exists():
raise FileNotFoundError(f"File {file} does not exist")
- for extra_type_description, extra_list in extra_type_dict.items():
+ for extra_type_description in extra_type_dict:
header, footer = get_header_and_footer(extra_type_description, file_format)
if insert_documentation(
file, extra_type_dict[extra_type_description], header, footer, add_comment
diff --git a/scripts/ci/pre_commit/update_example_dags_paths.py b/scripts/ci/pre_commit/update_example_dags_paths.py
index c7fd4aa834..8b2c461ec8 100755
--- a/scripts/ci/pre_commit/update_example_dags_paths.py
+++ b/scripts/ci/pre_commit/update_example_dags_paths.py
@@ -91,7 +91,7 @@ def replace_match(file: Path, line: str) -> str | None:
def find_matches(_file: Path):
new_lines = []
lines = _file.read_text().splitlines(keepends=True)
- for index, line in enumerate(lines):
+ for line in lines:
new_line = replace_match(_file, line)
if new_line is not None:
new_lines.append(new_line)
diff --git a/scripts/ci/pre_commit/vendor_k8s_json_schema.py b/scripts/ci/pre_commit/vendor_k8s_json_schema.py
index d5c8a9d552..3348a73840 100755
--- a/scripts/ci/pre_commit/vendor_k8s_json_schema.py
+++ b/scripts/ci/pre_commit/vendor_k8s_json_schema.py
@@ -63,7 +63,7 @@ defs = get_remote_schema(K8S_DEFINITIONS)
refs = set(find_refs(schema["properties"]))
# now we look for refs in refs
-for step in range(15):
+for _ in range(15):
starting_refs = refs
for ref in refs:
ref_id = ref.split("/")[-1]
diff --git a/scripts/ci/testing/summarize_junit_failures.py b/scripts/ci/testing/summarize_junit_failures.py
index 8ca34e03b5..ac15ee4175 100755
--- a/scripts/ci/testing/summarize_junit_failures.py
+++ b/scripts/ci/testing/summarize_junit_failures.py
@@ -43,7 +43,7 @@ def translate_classname(classname):
parts = classname.split(".")
- for offset, component in enumerate(parts, 1):
+ for offset, component in enumerate(parts, 1): # noqa: B007
candidate = context / component
if candidate.is_dir():
diff --git a/tests/cli/commands/test_internal_api_command.py b/tests/cli/commands/test_internal_api_command.py
index 2c41d16f75..9de857588a 100644
--- a/tests/cli/commands/test_internal_api_command.py
+++ b/tests/cli/commands/test_internal_api_command.py
@@ -125,7 +125,7 @@ class TestCliInternalAPI(_ComonCLIGunicornTestClass):
assert self._find_process(r"airflow internal-api --daemon", print_found_process=True)
console.print("[blue]Waiting for gunicorn processes:")
# wait for gunicorn to start
- for i in range(30):
+ for _ in range(30):
if self._find_process(r"^gunicorn"):
break
console.print("[blue]Waiting for gunicorn to start ...")
diff --git a/tests/cli/commands/test_webserver_command.py b/tests/cli/commands/test_webserver_command.py
index 28af1ef9df..07d95a9e5f 100644
--- a/tests/cli/commands/test_webserver_command.py
+++ b/tests/cli/commands/test_webserver_command.py
@@ -272,7 +272,7 @@ class TestCliWebServer(_ComonCLIGunicornTestClass):
assert self._find_process(r"airflow webserver", print_found_process=True)
console.print("[blue]Waiting for gunicorn processes:")
# wait for gunicorn to start
- for i in range(120):
+ for _ in range(120):
if self._find_process(r"^gunicorn"):
break
console.print("[blue]Waiting for gunicorn to start ...")
diff --git a/tests/integration/executors/test_celery_executor.py b/tests/integration/executors/test_celery_executor.py
index 26c2af03db..72e9ca9e10 100644
--- a/tests/integration/executors/test_celery_executor.py
+++ b/tests/integration/executors/test_celery_executor.py
@@ -140,7 +140,7 @@ class TestCeleryExecutor:
]
# "Enqueue" them. We don't have a real SimpleTaskInstance, so directly edit the dict
- for key, command, queue, task in task_tuples_to_send:
+ for key, command, queue, _ in task_tuples_to_send:
executor.queued_tasks[key] = (command, 1, queue, None)
executor.task_publish_retries[key] = 1
diff --git a/tests/integration/providers/apache/kafka/operators/test_consume.py b/tests/integration/providers/apache/kafka/operators/test_consume.py
index 3c315eea6f..58138a9b78 100644
--- a/tests/integration/providers/apache/kafka/operators/test_consume.py
+++ b/tests/integration/providers/apache/kafka/operators/test_consume.py
@@ -126,7 +126,7 @@ class TestConsumeFromTopic:
p = Producer(**{"bootstrap.servers": "broker:29092"})
- for x in range(20):
+ for _ in range(20):
p.produce(TOPIC, TOPIC)
assert len(p) == 20
diff --git a/tests/integration/providers/apache/kafka/triggers/test_await_message.py b/tests/integration/providers/apache/kafka/triggers/test_await_message.py
index 8f51390a48..3b371a51e8 100644
--- a/tests/integration/providers/apache/kafka/triggers/test_await_message.py
+++ b/tests/integration/providers/apache/kafka/triggers/test_await_message.py
@@ -64,7 +64,7 @@ class TestTrigger:
p = Producer(**{"bootstrap.servers": "broker:29092"})
- for x in range(20):
+ for _ in range(20):
p.produce(TOPIC, "not_this")
p.produce(TOPIC, TOPIC)
diff --git a/tests/jobs/test_backfill_job.py b/tests/jobs/test_backfill_job.py
index 7d445a7286..a50d942b09 100644
--- a/tests/jobs/test_backfill_job.py
+++ b/tests/jobs/test_backfill_job.py
@@ -1742,7 +1742,7 @@ class TestBackfillJob:
# create taskinstances and set states
dr1_tis = []
dr2_tis = []
- for i, (task, state) in enumerate(zip(tasks, states)):
+ for task, state in zip(tasks, states):
ti1 = TI(task, dr1.execution_date)
ti2 = TI(task, dr2.execution_date)
ti1.refresh_from_db()
diff --git a/tests/models/test_serialized_dag.py b/tests/models/test_serialized_dag.py
index 627943c6fd..c46d4e18a0 100644
--- a/tests/models/test_serialized_dag.py
+++ b/tests/models/test_serialized_dag.py
@@ -213,7 +213,7 @@ class TestSerializedDagModel:
excessive dag parsing.
"""
first_dag_hash = None
- for r in range(10):
+ for _ in range(10):
with DAG(
dag_id="example",
start_date=pendulum.datetime(2021, 1, 1, tz="UTC"),
diff --git a/tests/models/test_taskinstance.py b/tests/models/test_taskinstance.py
index fe01569e90..e4c9e17b21 100644
--- a/tests/models/test_taskinstance.py
+++ b/tests/models/test_taskinstance.py
@@ -370,7 +370,7 @@ class TestTaskInstance:
assert ti.state == State.QUEUED
dep_patch.return_value = TIDepStatus("mock_" + class_name, True, "mock")
- for dep_patch, method_patch in patch_dict.values():
+ for dep_patch, _ in patch_dict.values():
dep_patch.stop()
def test_mark_non_runnable_task_as_success(self, create_task_instance):
diff --git a/tests/providers/fab/auth_manager/test_security.py b/tests/providers/fab/auth_manager/test_security.py
index fecd5c4428..aa262f675f 100644
--- a/tests/providers/fab/auth_manager/test_security.py
+++ b/tests/providers/fab/auth_manager/test_security.py
@@ -997,7 +997,7 @@ def test_parent_dag_access_applies_to_subdag(app, security_manager, assert_user_
session.add_all([dag1, dag2, dag3])
session.commit()
security_manager.bulk_sync_roles(mock_roles)
- for dag in [dag1, dag2, dag3]:
+ for _ in [dag1, dag2, dag3]:
security_manager._sync_dag_view_permissions(
parent_dag_name, access_control={role_name: READ_WRITE}
)
diff --git a/tests/serialization/test_serialized_objects.py b/tests/serialization/test_serialized_objects.py
index 88f9165c66..1561c3a9a9 100644
--- a/tests/serialization/test_serialized_objects.py
+++ b/tests/serialization/test_serialized_objects.py
@@ -351,7 +351,7 @@ def test_all_pydantic_models_round_trip():
continue
relpath = str(p.relative_to(REPO_ROOT).stem)
mod = import_module(f"airflow.serialization.pydantic.{relpath}")
- for name, obj in inspect.getmembers(mod):
+ for _, obj in inspect.getmembers(mod):
if inspect.isclass(obj) and issubclass(obj, BaseModel):
if obj == BaseModel:
continue
diff --git a/tests/system/providers/cncf/kubernetes/example_kubernetes_decorator.py b/tests/system/providers/cncf/kubernetes/example_kubernetes_decorator.py
index 2348f31bdf..3d989080d2 100644
--- a/tests/system/providers/cncf/kubernetes/example_kubernetes_decorator.py
+++ b/tests/system/providers/cncf/kubernetes/example_kubernetes_decorator.py
@@ -49,7 +49,7 @@ with DAG(
for i in range(n):
# inner loop to handle number of columns
# values changing acc. to outer loop
- for j in range(i + 1):
+ for _ in range(i + 1):
# printing stars
print("* ", end="")
diff --git a/tests/test_utils/perf/perf_kit/memory.py b/tests/test_utils/perf/perf_kit/memory.py
index 471ed1282a..b236630f5f 100644
--- a/tests/test_utils/perf/perf_kit/memory.py
+++ b/tests/test_utils/perf/perf_kit/memory.py
@@ -29,7 +29,7 @@ def _get_process_memory():
def _human_readable_size(size, decimal_places=3):
- for unit in ["B", "KiB", "MiB", "GiB", "TiB"]:
+ for unit in ["B", "KiB", "MiB", "GiB", "TiB"]: # noqa: B007
if size < 1024.0:
break
size /= 1024.0
diff --git a/tests/utils/test_log_handlers.py b/tests/utils/test_log_handlers.py
index 7f84b6d9f1..b6811830ee 100644
--- a/tests/utils/test_log_handlers.py
+++ b/tests/utils/test_log_handlers.py
@@ -576,7 +576,7 @@ AIRFLOW_CTX_DAG_RUN_ID=manual__2022-11-16T08:05:52.324532+00:00
def test_parse_timestamps():
actual = []
- for timestamp, idx, line in _parse_timestamps_in_log_file(log_sample.splitlines()):
+ for timestamp, _, _ in _parse_timestamps_in_log_file(log_sample.splitlines()):
actual.append(timestamp)
assert actual == [
pendulum.parse("2022-11-16T00:05:54.278000-08:00"),