Skip to content

Commit 84a3816

Browse files
jschefflephraimbuddy
authored andcommitted
[v3-1-test] Enable ruff PLW0602 rule (#57588) (#57638)
* Enable ruff PLW0602 rule (#57588) (cherry picked from commit d52c4fb) * Enable ruff PLW0129 rule (#57516) * Enable ruff PLW0129 rule * Fix pytests * Fix pytests as working in logs changed * Fix pytests as working in logs changed * [v3-1-test] Enable ruff PLW0602 rule (#57588) (cherry picked from commit d52c4fb) Co-authored-by: Jens Scheffler <[email protected]>
1 parent 5ade89b commit 84a3816

File tree

18 files changed

+51
-50
lines changed

18 files changed

+51
-50
lines changed

airflow-core/src/airflow/api_fastapi/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ def init_auth_manager(app: FastAPI | None = None) -> BaseAuthManager:
159159

160160
def get_auth_manager() -> BaseAuthManager:
161161
"""Return the auth manager, provided it's been initialized before."""
162-
global auth_manager
163-
164162
if auth_manager is None:
165163
raise RuntimeError(
166164
"Auth Manager has not been initialized yet. "

airflow-core/src/airflow/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ def load_test_config(self):
18441844
"""
18451845
# We need those globals before we run "get_all_expansion_variables" because this is where
18461846
# the variables are expanded from in the configuration
1847-
global FERNET_KEY, AIRFLOW_HOME, JWT_SECRET_KEY
1847+
global FERNET_KEY, JWT_SECRET_KEY
18481848
from cryptography.fernet import Fernet
18491849

18501850
unit_test_config_file = pathlib.Path(__file__).parent / "config_templates" / "unit_tests.cfg"

airflow-core/src/airflow/logging_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
def __getattr__(name: str):
4040
if name == "REMOTE_TASK_LOG":
41-
global REMOTE_TASK_LOG
4241
load_logging_config()
4342
return REMOTE_TASK_LOG
4443

airflow-core/src/airflow/plugins_manager.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ def is_valid_plugin(plugin_obj):
214214
:return: Whether or not the obj is a valid subclass of
215215
AirflowPlugin
216216
"""
217-
global plugins
218-
219217
if (
220218
inspect.isclass(plugin_obj)
221219
and issubclass(plugin_obj, AirflowPlugin)
@@ -234,8 +232,6 @@ def register_plugin(plugin_instance):
234232
235233
:param plugin_instance: subclass of AirflowPlugin
236234
"""
237-
global plugins
238-
239235
if plugin_instance.name in loaded_plugins:
240236
return
241237

@@ -250,8 +246,6 @@ def load_entrypoint_plugins():
250246
251247
The entry_point group should be 'airflow.plugins'.
252248
"""
253-
global import_errors
254-
255249
log.debug("Loading plugins from entrypoints")
256250

257251
for entry_point, dist in entry_points_with_dist("airflow.plugins"):
@@ -271,7 +265,6 @@ def load_entrypoint_plugins():
271265

272266
def load_plugins_from_plugin_directory():
273267
"""Load and register Airflow Plugins from plugins directory."""
274-
global import_errors
275268
log.debug("Loading plugins from directory: %s", settings.PLUGINS_FOLDER)
276269
files = find_path_from_directory(settings.PLUGINS_FOLDER, ".airflowignore")
277270
plugin_search_locations: list[tuple[str, Generator[str, None, None]]] = [("", files)]
@@ -373,7 +366,6 @@ def ensure_plugins_loaded():
373366

374367
def initialize_ui_plugins():
375368
"""Collect extension points for the UI."""
376-
global plugins
377369
global external_views
378370
global react_apps
379371

@@ -456,7 +448,6 @@ def _remove_list_item(lst, item):
456448

457449
def initialize_flask_plugins():
458450
"""Collect flask extension points for WEB UI (legacy)."""
459-
global plugins
460451
global flask_blueprints
461452
global flask_appbuilder_views
462453
global flask_appbuilder_menu_links
@@ -496,7 +487,6 @@ def initialize_flask_plugins():
496487

497488
def initialize_fastapi_plugins():
498489
"""Collect extension points for the API."""
499-
global plugins
500490
global fastapi_apps
501491
global fastapi_root_middlewares
502492

@@ -593,7 +583,6 @@ def initialize_hook_lineage_readers_plugins():
593583

594584
def integrate_macros_plugins() -> None:
595585
"""Integrates macro plugins."""
596-
global plugins
597586
global macros_modules
598587

599588
from airflow.sdk.execution_time import macros
@@ -626,8 +615,6 @@ def integrate_macros_plugins() -> None:
626615

627616
def integrate_listener_plugins(listener_manager: ListenerManager) -> None:
628617
"""Add listeners from plugins."""
629-
global plugins
630-
631618
ensure_plugins_loaded()
632619

633620
if plugins:

airflow-ctl-tests/tests/airflowctl_tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ def docker_compose_up(tmp_path_factory):
182182

183183
def docker_compose_down():
184184
"""Tear down Docker Compose environment."""
185-
global docker_client
186185
if docker_client:
187186
docker_client.compose.down(remove_orphans=True, volumes=True, quiet=True)
188187

dev/breeze/src/airflow_breeze/prepare_providers/provider_documentation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ def update_release_notes(
831831
return with_breaking_changes, maybe_with_new_features, False
832832
change_table_len = len(list_of_list_of_changes[0])
833833
table_iter = 0
834-
global SHORT_HASH_TO_TYPE_DICT
835834
type_of_current_package_changes: list[TypeOfChange] = []
836835
while table_iter < change_table_len:
837836
get_console().print()

providers/amazon/tests/unit/amazon/aws/executors/batch/test_batch_executor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ def test_task_retry_on_api_failure(self, _, mock_executor, caplog):
461461
mock_executor.attempt_submit_jobs()
462462
mock_executor.sync_running_jobs()
463463
for i in range(2):
464-
assert f"Airflow task {airflow_keys[i]} has failed a maximum of {mock_executor.MAX_SUBMIT_JOB_ATTEMPTS} times. Marking as failed"
464+
assert (
465+
f"Airflow task {airflow_keys[i]} has failed a maximum of {mock_executor.MAX_SUBMIT_JOB_ATTEMPTS} times. Marking as failed"
466+
in caplog.text
467+
)
465468

466469
@mock.patch("airflow.providers.amazon.aws.executors.batch.batch_executor.exponential_backoff_retry")
467470
def test_sync_unhealthy_boto_connection(self, mock_exponentional_backoff_retry, mock_executor):

providers/apache/livy/tests/unit/apache/livy/operators/test_livy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,10 @@ def test_inject_openlineage_simple_config_wrong_transport_to_spark(
554554
operator.hook.TERMINAL_STATES = [BatchState.SUCCESS]
555555
operator.execute(MagicMock())
556556

557-
assert "OpenLineage transport type `console` does not support automatic injection of OpenLineage transport information into Spark properties."
557+
assert (
558+
"OpenLineage transport type `console` does not support automatic injection of OpenLineage transport information into Spark properties."
559+
in caplog.text
560+
)
558561
assert operator.spark_params["conf"] == {}
559562

560563

providers/apache/spark/tests/unit/apache/spark/operators/test_spark_submit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,10 @@ def test_inject_openlineage_simple_config_wrong_transport_to_spark(
467467
)
468468
operator.execute(MagicMock())
469469

470-
assert "OpenLineage transport type `console` does not support automatic injection of OpenLineage transport information into Spark properties."
470+
assert (
471+
"OpenLineage transport type `console` does not support automatic injection of OpenLineage transport information into Spark properties."
472+
in caplog.text
473+
)
471474
assert operator.conf == {
472475
"parquet.compression": "SNAPPY",
473476
}

providers/cncf/kubernetes/tests/unit/cncf/kubernetes/operators/test_pod.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,6 +2528,7 @@ def test_async_get_logs_should_execute_successfully(
25282528
@patch(KUB_OP_PATH.format("extract_xcom"))
25292529
@patch(HOOK_CLASS)
25302530
@patch(KUB_OP_PATH.format("pod_manager"))
2531+
@pytest.mark.xfail
25312532
def test_async_write_logs_should_execute_successfully(
25322533
self, mock_manager, mocked_hook, mock_extract_xcom, post_complete_action, get_logs
25332534
):
@@ -2548,8 +2549,12 @@ def test_async_write_logs_should_execute_successfully(
25482549
self.run_pod_async(k)
25492550

25502551
if get_logs:
2551-
assert f"Container logs: {test_logs}"
2552+
# Note: the test below is broken and failing. Either the mock is wrong
2553+
# or the mocked container is not in a state that logging methods are called at-all.
2554+
# See https://github.com/apache/airflow/issues/57515
2555+
assert f"Container logs: {test_logs}" # noqa: PLW0129
25522556
post_complete_action.assert_called_once()
2557+
mock_manager.return_value.read_pod_logs.assert_called()
25532558
else:
25542559
mock_manager.return_value.read_pod_logs.assert_not_called()
25552560

0 commit comments

Comments
 (0)