Skip to content

Commit 4b8cd25

Browse files
authored
Upgrade ruff to latest version (0.12.1) (#52562)
Fixes #52551
1 parent 2bdb515 commit 4b8cd25

33 files changed

Lines changed: 324 additions & 308 deletions

File tree

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ repos:
427427
types_or: [python, pyi]
428428
args: [--fix]
429429
require_serial: true
430-
additional_dependencies: ['ruff==0.11.13']
430+
additional_dependencies: ['ruff==0.12.1']
431431
exclude: ^airflow-core/tests/unit/dags/test_imports\.py$|^performance/tests/test_.*\.py$
432432
- id: ruff-format
433433
name: Run 'ruff format'
@@ -437,7 +437,7 @@ repos:
437437
types_or: [python, pyi]
438438
args: []
439439
require_serial: true
440-
additional_dependencies: ['ruff==0.11.13']
440+
additional_dependencies: ['ruff==0.12.1']
441441
exclude: ^airflow-core/tests/unit/dags/test_imports\.py$
442442
- id: replace-bad-characters
443443
name: Replace bad characters
@@ -1590,7 +1590,7 @@ repos:
15901590
name: Check imports in providers
15911591
entry: ./scripts/ci/pre_commit/check_imports_in_providers.py
15921592
language: python
1593-
additional_dependencies: ['rich>=12.4.4', 'ruff==0.11.13']
1593+
additional_dependencies: ['rich>=12.4.4', 'ruff==0.12.1']
15941594
files: ^providers/.*/src/airflow/providers/.*version_compat.*\.py$
15951595
require_serial: true
15961596
## ONLY ADD PRE-COMMITS HERE THAT REQUIRE CI IMAGE

airflow-core/src/airflow/utils/log/logging_mixin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import sys
2525
from io import TextIOBase, UnsupportedOperation
2626
from logging import Handler, StreamHandler
27-
from typing import IO, TYPE_CHECKING, Any, Optional, TypeVar, cast
27+
from typing import IO, TYPE_CHECKING, Any, TypeVar, cast
2828

2929
if TYPE_CHECKING:
3030
from logging import Logger
@@ -72,9 +72,9 @@ class LoggingMixin:
7272
# Parent logger used by this class. It should match one of the loggers defined in the
7373
# `logging_config_class`. By default, this attribute is used to create the final name of the logger, and
7474
# will prefix the `_logger_name` with a separating dot.
75-
_log_config_logger_name: Optional[str] = None # noqa: UP007
75+
_log_config_logger_name: str | None = None
7676

77-
_logger_name: Optional[str] = None # noqa: UP007
77+
_logger_name: str | None = None
7878

7979
def __init__(self, context=None):
8080
self._set_context(context)

airflow-core/tests/unit/always/test_providers_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ def test_providers_are_loaded(self):
7272
assert self._caplog.records == []
7373

7474
def test_hooks_deprecation_warnings_generated(self):
75+
providers_manager = ProvidersManager()
76+
providers_manager._provider_dict["test-package"] = ProviderInfo(
77+
version="0.0.1",
78+
data={"hook-class-names": ["airflow.providers.sftp.hooks.sftp.SFTPHook"]},
79+
)
7580
with pytest.warns(expected_warning=DeprecationWarning, match="hook-class-names") as warning_records:
76-
providers_manager = ProvidersManager()
77-
providers_manager._provider_dict["test-package"] = ProviderInfo(
78-
version="0.0.1",
79-
data={"hook-class-names": ["airflow.providers.sftp.hooks.sftp.SFTPHook"]},
80-
)
8181
providers_manager._discover_hooks()
8282
assert warning_records
8383

airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ def test_get_task_group_states_with_multiple_task(self, client, session, dag_mak
19091909
},
19101910
}
19111911

1912-
def test_get_task_group_states_with_logical_dates(self, client, session, dag_maker, serialized=True):
1912+
def test_get_task_group_states_with_logical_dates(self, client, session, dag_maker):
19131913
with dag_maker("test_get_task_group_states_with_logical_dates", serialized=True):
19141914
with TaskGroup("group1"):
19151915
EmptyOperator(task_id="task1")

airflow-core/tests/unit/core/test_configuration.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,11 +1040,14 @@ def test_deprecated_options(self):
10401040
# Remove it so we are sure we use the right setting
10411041
conf.remove_option("celery", "worker_concurrency")
10421042

1043-
with pytest.warns(DeprecationWarning):
1043+
with pytest.warns(DeprecationWarning, match="celeryd_concurrency"):
10441044
with mock.patch.dict("os.environ", AIRFLOW__CELERY__CELERYD_CONCURRENCY="99"):
10451045
assert conf.getint("celery", "worker_concurrency") == 99
10461046

1047-
with pytest.warns(DeprecationWarning), conf_vars({("celery", "celeryd_concurrency"): "99"}):
1047+
with (
1048+
pytest.warns(DeprecationWarning, match="celeryd_concurrency"),
1049+
conf_vars({("celery", "celeryd_concurrency"): "99"}),
1050+
):
10481051
assert conf.getint("celery", "worker_concurrency") == 99
10491052

10501053
@pytest.mark.parametrize(
@@ -1109,13 +1112,13 @@ def test_deprecated_options_cmd(self):
11091112
):
11101113
conf.remove_option("celery", "result_backend")
11111114
with conf_vars({("celery", "celery_result_backend_cmd"): "/bin/echo 99"}):
1112-
with pytest.warns(DeprecationWarning):
1113-
tmp = None
1114-
if "AIRFLOW__CELERY__RESULT_BACKEND" in os.environ:
1115-
tmp = os.environ.pop("AIRFLOW__CELERY__RESULT_BACKEND")
1115+
tmp = None
1116+
if "AIRFLOW__CELERY__RESULT_BACKEND" in os.environ:
1117+
tmp = os.environ.pop("AIRFLOW__CELERY__RESULT_BACKEND")
1118+
with pytest.warns(DeprecationWarning, match="result_backend"):
11161119
assert conf.getint("celery", "result_backend") == 99
1117-
if tmp:
1118-
os.environ["AIRFLOW__CELERY__RESULT_BACKEND"] = tmp
1120+
if tmp:
1121+
os.environ["AIRFLOW__CELERY__RESULT_BACKEND"] = tmp
11191122

11201123
def test_deprecated_values_from_conf(self):
11211124
test_conf = AirflowConfigParser(
@@ -1135,7 +1138,7 @@ def test_deprecated_values_from_conf(self):
11351138

11361139
with pytest.warns(FutureWarning):
11371140
test_conf.validate()
1138-
assert test_conf.get("core", "hostname_callable") == "airflow.utils.net.getfqdn"
1141+
assert test_conf.get("core", "hostname_callable") == "airflow.utils.net.getfqdn"
11391142

11401143
@pytest.mark.parametrize(
11411144
"old, new",
@@ -1160,19 +1163,19 @@ def test_deprecated_env_vars_upgraded_and_removed(self, old, new):
11601163
old_env_var = test_conf._env_var_name(old_section, old_key)
11611164
new_env_var = test_conf._env_var_name(new_section, new_key)
11621165

1163-
with pytest.warns(FutureWarning):
1164-
with mock.patch.dict("os.environ", **{old_env_var: old_value}):
1165-
# Can't start with the new env var existing...
1166-
os.environ.pop(new_env_var, None)
1166+
with mock.patch.dict("os.environ", **{old_env_var: old_value}):
1167+
# Can't start with the new env var existing...
1168+
os.environ.pop(new_env_var, None)
11671169

1170+
with pytest.warns(FutureWarning):
11681171
test_conf.validate()
1169-
assert test_conf.get(new_section, new_key) == new_value
1170-
# We also need to make sure the deprecated env var is removed
1171-
# so that any subprocesses don't use it in place of our updated
1172-
# value.
1173-
assert old_env_var not in os.environ
1174-
# and make sure we track the old value as well, under the new section/key
1175-
assert test_conf.upgraded_values[(new_section, new_key)] == old_value
1172+
assert test_conf.get(new_section, new_key) == new_value
1173+
# We also need to make sure the deprecated env var is removed
1174+
# so that any subprocesses don't use it in place of our updated
1175+
# value.
1176+
assert old_env_var not in os.environ
1177+
# and make sure we track the old value as well, under the new section/key
1178+
assert test_conf.upgraded_values[(new_section, new_key)] == old_value
11761179

11771180
@pytest.mark.parametrize(
11781181
"conf_dict",
@@ -1200,10 +1203,10 @@ def make_config():
12001203
test_conf.validate()
12011204
return test_conf
12021205

1203-
with pytest.warns(FutureWarning):
1204-
with mock.patch.dict("os.environ", AIRFLOW__CORE__HOSTNAME_CALLABLE="airflow.utils.net:getfqdn"):
1206+
with mock.patch.dict("os.environ", AIRFLOW__CORE__HOSTNAME_CALLABLE="airflow.utils.net:getfqdn"):
1207+
with pytest.warns(FutureWarning):
12051208
test_conf = make_config()
1206-
assert test_conf.get("core", "hostname_callable") == "airflow.utils.net.getfqdn"
1209+
assert test_conf.get("core", "hostname_callable") == "airflow.utils.net.getfqdn"
12071210

12081211
with reset_warning_registry():
12091212
with warnings.catch_warnings(record=True) as warning:

airflow-core/tests/unit/datasets/test_dataset.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@
7373
),
7474
)
7575
def test_backward_compat_import_before_airflow_3_2(module_path, attr_name, expected_value, warning_message):
76-
with pytest.warns() as record:
77-
import importlib
76+
import importlib
7877

78+
with pytest.warns() as record:
7979
mod = importlib.import_module(module_path, __name__)
8080
attr = getattr(mod, attr_name)
81-
assert f"{attr.__module__}.{attr.__name__}" == expected_value
82-
81+
assert f"{attr.__module__}.{attr.__name__}" == expected_value
8382
assert record[0].category is DeprecationWarning
8483
assert str(record[0].message) == warning_message
84+
85+
86+
# ruff: noqa: PT031

airflow-core/tests/unit/listeners/test_listeners.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def clean_listener_manager():
6969

7070

7171
@provide_session
72-
def test_listener_gets_calls(create_task_instance, session=None):
72+
def test_listener_gets_calls(create_task_instance, session):
7373
lm = get_listener_manager()
7474
lm.add_listener(full_listener)
7575

@@ -84,7 +84,7 @@ def test_listener_gets_calls(create_task_instance, session=None):
8484

8585

8686
@provide_session
87-
def test_multiple_listeners(create_task_instance, session=None):
87+
def test_multiple_listeners(create_task_instance, session):
8888
lm = get_listener_manager()
8989
lm.add_listener(full_listener)
9090
lm.add_listener(lifecycle_listener)
@@ -105,7 +105,7 @@ def test_multiple_listeners(create_task_instance, session=None):
105105

106106

107107
@provide_session
108-
def test_listener_gets_only_subscribed_calls(create_task_instance, session=None):
108+
def test_listener_gets_only_subscribed_calls(create_task_instance, session):
109109
lm = get_listener_manager()
110110
lm.add_listener(partial_listener)
111111

@@ -130,7 +130,7 @@ def test_listener_suppresses_exceptions(create_task_instance, session, cap_struc
130130

131131

132132
@provide_session
133-
def test_listener_captures_failed_taskinstances(create_task_instance_of_operator, session=None):
133+
def test_listener_captures_failed_taskinstances(create_task_instance_of_operator, session):
134134
lm = get_listener_manager()
135135
lm.add_listener(full_listener)
136136

@@ -145,7 +145,7 @@ def test_listener_captures_failed_taskinstances(create_task_instance_of_operator
145145

146146

147147
@provide_session
148-
def test_listener_captures_longrunning_taskinstances(create_task_instance_of_operator, session=None):
148+
def test_listener_captures_longrunning_taskinstances(create_task_instance_of_operator, session):
149149
lm = get_listener_manager()
150150
lm.add_listener(full_listener)
151151

@@ -159,7 +159,7 @@ def test_listener_captures_longrunning_taskinstances(create_task_instance_of_ope
159159

160160

161161
@provide_session
162-
def test_class_based_listener(create_task_instance, session=None):
162+
def test_class_based_listener(create_task_instance, session):
163163
lm = get_listener_manager()
164164
listener = class_listener.ClassBasedListener()
165165
lm.add_listener(listener)

airflow-core/tests/unit/models/test_dagbag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ def test_capture_warnings(self):
10321032
with pytest.warns(UserWarning, match="(Foo|Bar|Baz)") as ctx:
10331033
with _capture_with_reraise() as cw:
10341034
self.raise_warnings()
1035-
assert len(cw) == 3
1035+
assert len(cw) == 3
10361036
assert len(ctx.list) == 3
10371037

10381038
def test_capture_warnings_with_parent_error_filter(self):

airflow-core/tests/unit/models/test_taskinstance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def test_pool_slots_property(self):
404404
)
405405

406406
@provide_session
407-
def test_ti_updates_with_task(self, create_task_instance, session=None):
407+
def test_ti_updates_with_task(self, create_task_instance, session):
408408
"""
409409
test that updating the executor_config propagates to the TaskInstance DB
410410
"""
@@ -1269,7 +1269,7 @@ def test_respects_prev_dagrun_dep(self, create_task_instance):
12691269
)
12701270
@provide_session
12711271
def test_are_dependents_done(
1272-
self, downstream_ti_state, expected_are_dependents_done, create_task_instance, session=None
1272+
self, downstream_ti_state, expected_are_dependents_done, create_task_instance, session
12731273
):
12741274
ti = create_task_instance(session=session)
12751275
dag = ti.task.dag
@@ -2288,7 +2288,7 @@ def test_template_with_json_variable_missing(self, create_task_instance, session
22882288
ti.task.render_template('{{ var.json.get("missing_variable") }}', context)
22892289

22902290
@provide_session
2291-
def test_handle_failure(self, dag_maker, session=None):
2291+
def test_handle_failure(self, dag_maker, session):
22922292
class CustomOp(BaseOperator):
22932293
def execute(self, context): ...
22942294

airflow-core/tests/unit/models/test_timestamp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def add_log(execdate, session, dag_maker, timezone_override=None):
5454

5555

5656
@provide_session
57-
def test_timestamp_behaviour(dag_maker, session=None):
57+
def test_timestamp_behaviour(dag_maker, session):
5858
execdate = timezone.utcnow()
5959
with time_machine.travel(execdate, tick=False):
6060
current_time = timezone.utcnow()
@@ -66,7 +66,7 @@ def test_timestamp_behaviour(dag_maker, session=None):
6666

6767

6868
@provide_session
69-
def test_timestamp_behaviour_with_timezone(dag_maker, session=None):
69+
def test_timestamp_behaviour_with_timezone(dag_maker, session):
7070
execdate = timezone.utcnow()
7171
with time_machine.travel(execdate, tick=False):
7272
current_time = timezone.utcnow()

0 commit comments

Comments
 (0)