This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v3-2-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-2-test by this push:
new a016b7c85d8 Use contextlib.suppress instead of try-except-pass and
re-enable SIM105 (#66193) (#66264)
a016b7c85d8 is described below
commit a016b7c85d8587d86a5e01f214269b72cbe0b8bf
Author: Jens Scheffler <[email protected]>
AuthorDate: Sat May 2 14:33:18 2026 +0200
Use contextlib.suppress instead of try-except-pass and re-enable SIM105
(#66193) (#66264)
(cherry picked from commit 251fe925b5484fe6ff11e6b6de46ef8099c320c9)
Signed-off-by: ColtenOuO <[email protected]>
Co-authored-by: Colten <[email protected]>
---
airflow-core/src/airflow/cli/hot_reload.py | 5 ++---
airflow-core/tests/unit/api_fastapi/core_api/test_app.py | 5 ++---
airflow-core/tests/unit/jobs/test_triggerer_job.py | 6 +++---
airflow-core/tests/unit/utils/test_process_utils.py | 4 +---
dev/breeze/src/airflow_breeze/utils/airflow_release_validator.py | 9 +++------
dev/breeze/src/airflow_breeze/utils/reproducible.py | 6 ++----
dev/ide_setup/setup_idea.py | 9 +++------
pyproject.toml | 2 +-
task-sdk/src/airflow/sdk/execution_time/context.py | 4 +---
9 files changed, 18 insertions(+), 32 deletions(-)
diff --git a/airflow-core/src/airflow/cli/hot_reload.py
b/airflow-core/src/airflow/cli/hot_reload.py
index ecf64c2781d..56fb97efcb9 100644
--- a/airflow-core/src/airflow/cli/hot_reload.py
+++ b/airflow-core/src/airflow/cli/hot_reload.py
@@ -19,6 +19,7 @@
from __future__ import annotations
+import contextlib
import os
import signal
import sys
@@ -94,10 +95,8 @@ def _terminate_process_tree(
# Terminate all children first
for child in children:
- try:
+ with contextlib.suppress(psutil.NoSuchProcess,
psutil.AccessDenied):
child.terminate()
- except (psutil.NoSuchProcess, psutil.AccessDenied):
- pass
# Terminate the parent
parent.terminate()
diff --git a/airflow-core/tests/unit/api_fastapi/core_api/test_app.py
b/airflow-core/tests/unit/api_fastapi/core_api/test_app.py
index a30c803f50c..4aadcdd005a 100644
--- a/airflow-core/tests/unit/api_fastapi/core_api/test_app.py
+++ b/airflow-core/tests/unit/api_fastapi/core_api/test_app.py
@@ -16,6 +16,7 @@
# under the License.
from __future__ import annotations
+import contextlib
import inspect
import typing
@@ -70,10 +71,8 @@ class TestStreamingEndpointSessionScope:
continue
returns_streaming = hints.get("return") is StreamingResponse
if not returns_streaming:
- try:
+ with contextlib.suppress(OSError, TypeError):
returns_streaming = "StreamingResponse" in
inspect.getsource(route.endpoint)
- except (OSError, TypeError):
- pass
if not returns_streaming:
continue
fqn = f"{route.endpoint.__module__}.{route.endpoint.__qualname__}"
diff --git a/airflow-core/tests/unit/jobs/test_triggerer_job.py
b/airflow-core/tests/unit/jobs/test_triggerer_job.py
index 3761189bfeb..bf5d6de6ec8 100644
--- a/airflow-core/tests/unit/jobs/test_triggerer_job.py
+++ b/airflow-core/tests/unit/jobs/test_triggerer_job.py
@@ -18,6 +18,7 @@
from __future__ import annotations
import asyncio
+import contextlib
import datetime
import itertools
import os
@@ -1273,10 +1274,9 @@ class TestTriggererJobRunner:
# We don't need to run the full _execute, just verify Stats.initialize
is called
# before TriggerRunnerSupervisor.start
with patch.object(job_runner, "register_signals"):
- try:
+ # We expect this to fail since we're mocking
+ with contextlib.suppress(Exception):
job_runner._execute()
- except Exception:
- pass # We expect this to fail since we're mocking
# Verify Stats.initialize was called with the expected configuration
parameters
stats_init_mock.assert_called_once()
diff --git a/airflow-core/tests/unit/utils/test_process_utils.py
b/airflow-core/tests/unit/utils/test_process_utils.py
index 5d054db7786..5ebc599b6b6 100644
--- a/airflow-core/tests/unit/utils/test_process_utils.py
+++ b/airflow-core/tests/unit/utils/test_process_utils.py
@@ -80,10 +80,8 @@ time.sleep(300)
assert not psutil.pid_exists(parent_pid)
assert not psutil.pid_exists(child_pid)
finally:
- try:
+ with suppress(OSError):
os.kill(parent.pid, signal.SIGKILL)
- except OSError:
- pass
parent.stdout.close()
parent.wait()
diff --git a/dev/breeze/src/airflow_breeze/utils/airflow_release_validator.py
b/dev/breeze/src/airflow_breeze/utils/airflow_release_validator.py
index cbd46cc48f0..889e02eeb51 100644
--- a/dev/breeze/src/airflow_breeze/utils/airflow_release_validator.py
+++ b/dev/breeze/src/airflow_breeze/utils/airflow_release_validator.py
@@ -16,6 +16,7 @@
# under the License.
from __future__ import annotations
+import contextlib
import filecmp
import shutil
import tarfile
@@ -468,15 +469,11 @@ class AirflowReleaseValidator(ReleaseValidator):
for line in result.stdout.split("\n"):
if "Unapproved:" in line:
- try:
+ with contextlib.suppress(IndexError, ValueError):
unapproved = int(line.split("Unapproved:")[1].split()[0])
- except (IndexError, ValueError):
- pass
if "Unknown:" in line:
- try:
+ with contextlib.suppress(IndexError, ValueError):
unknown = int(line.split("Unknown:")[1].split()[0])
- except (IndexError, ValueError):
- pass
details = []
if error_lines:
diff --git a/dev/breeze/src/airflow_breeze/utils/reproducible.py
b/dev/breeze/src/airflow_breeze/utils/reproducible.py
index 218598dd660..b3554abd514 100644
--- a/dev/breeze/src/airflow_breeze/utils/reproducible.py
+++ b/dev/breeze/src/airflow_breeze/utils/reproducible.py
@@ -134,11 +134,9 @@ def repack_deterministically(
entry_path.chmod(new_mode)
else:
# for symlinks on the other hand set rwx for all -
to match Linux on MacOS
- try:
+ # (on platforms like Linux symlink permissions
cannot be changed)
+ with contextlib.suppress(NotImplementedError):
entry_path.chmod(0o777, follow_symlinks=False)
- except NotImplementedError:
- # on platforms like Linux symlink permissions
cannot be changed
- pass
arcname = entry
if prepend_path is not None:
arcname =
os.path.normpath(os.path.join(prepend_path, arcname))
diff --git a/dev/ide_setup/setup_idea.py b/dev/ide_setup/setup_idea.py
index e13959890b1..7cf570d6da3 100755
--- a/dev/ide_setup/setup_idea.py
+++ b/dev/ide_setup/setup_idea.py
@@ -25,6 +25,7 @@
from __future__ import annotations
import argparse
+import contextlib
import os
import platform
import re
@@ -481,10 +482,8 @@ def _kill_jetbrains_ides(*, confirm: bool = False) -> bool:
if not should_kill:
return True
for pid, _comm in pids:
- try:
+ with contextlib.suppress(OSError):
os.kill(pid, signal.SIGTERM)
- except OSError:
- pass
# Wait up to 5 seconds for graceful shutdown.
for _ in range(10):
remaining = _find_jetbrains_pids()
@@ -495,10 +494,8 @@ def _kill_jetbrains_ides(*, confirm: bool = False) -> bool:
# Force-kill any remaining processes.
remaining = _find_jetbrains_pids()
for pid, _comm in remaining:
- try:
+ with contextlib.suppress(OSError):
os.kill(pid, signal.SIGKILL)
- except OSError:
- pass
print("[green]JetBrains IDE processes force-killed.[/]\n")
return True
diff --git a/pyproject.toml b/pyproject.toml
index 5679d3944a9..e3105b299d1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -653,6 +653,7 @@ extend-select = [
"RET506", # Unnecessary {branch} after raise statement
"RET507", # Unnecessary {branch} after continue statement
"RET508", # Unnecessary {branch} after break statement
+ "SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
]
ignore = [
"D100", # Unwanted; Docstring at the top of every file.
@@ -685,7 +686,6 @@ ignore = [
"COM819",
"E501", # Formatted code may exceed the line length, leading to
line-too-long (E501) errors.
"ASYNC110", # TODO: Use `anyio.Event` instead of awaiting `anyio.sleep` in
a `while` loop
- "SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
]
unfixable = [
# PT022 replace empty `yield` to empty `return`. Might be fixed with a
combination of PLR1711
diff --git a/task-sdk/src/airflow/sdk/execution_time/context.py
b/task-sdk/src/airflow/sdk/execution_time/context.py
index db5a75e10c1..a60ca453f1b 100644
--- a/task-sdk/src/airflow/sdk/execution_time/context.py
+++ b/task-sdk/src/airflow/sdk/execution_time/context.py
@@ -645,10 +645,8 @@ class InletEventsAccessor(Sequence["AssetEventResult"]):
return list(resp.iter_asset_event_results())
def _reset_cache(self) -> None:
- try:
+ with contextlib.suppress(AttributeError):
del self._asset_events
- except AttributeError:
- pass
def __iter__(self) -> Iterator[AssetEventResult]:
return iter(self._asset_events)