From 540de6bb15ae4825dd16cff4e9940f4670c5cc69 Mon Sep 17 00:00:00 2001 From: Andrey Anshin Date: Sat, 17 Feb 2024 03:36:03 +0400 Subject: [PATCH] Replace other Python 3.11 and 3.12 deprecations (#37478) * Replace usage of deprecated typing classes (Python 3.12) * Replace usage of locale.getdefaultlocale (Python 3.11) (cherry picked from commit ef70594358f5e5e3aa7c27de621869aa5d4b2d27) --- airflow/cli/commands/info_command.py | 2 +- airflow/exceptions.py | 3 ++- airflow/models/expandinput.py | 3 ++- pyproject.toml | 6 ++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/airflow/cli/commands/info_command.py b/airflow/cli/commands/info_command.py index 3d72e4641ebe8..83c62f71886a9 100644 --- a/airflow/cli/commands/info_command.py +++ b/airflow/cli/commands/info_command.py @@ -259,7 +259,7 @@ def _system_info(self): operating_system = OperatingSystem.get_current() arch = Architecture.get_current() uname = platform.uname() - _locale = locale.getdefaultlocale() + _locale = locale.getlocale() python_location = self.anonymizer.process_path(sys.executable) python_version = sys.version.replace("\n", " ") diff --git a/airflow/exceptions.py b/airflow/exceptions.py index 2ca75cbbf874f..f747640c77685 100644 --- a/airflow/exceptions.py +++ b/airflow/exceptions.py @@ -22,12 +22,13 @@ import warnings from http import HTTPStatus -from typing import TYPE_CHECKING, Any, NamedTuple, Sized +from typing import TYPE_CHECKING, Any, NamedTuple from airflow.utils.trigger_rule import TriggerRule if TYPE_CHECKING: import datetime + from collections.abc import Sized from airflow.models import DAG, DagRun diff --git a/airflow/models/expandinput.py b/airflow/models/expandinput.py index 44f26a34830b5..a20280e5a1111 100644 --- a/airflow/models/expandinput.py +++ b/airflow/models/expandinput.py @@ -20,7 +20,8 @@ import collections.abc import functools import operator -from typing import TYPE_CHECKING, Any, Dict, Iterable, Mapping, NamedTuple, Sequence, Sized, Union +from collections.abc import Sized +from typing import TYPE_CHECKING, Any, Dict, Iterable, Mapping, NamedTuple, Sequence, Union import attr diff --git a/pyproject.toml b/pyproject.toml index 67cf05952ad28..34e8faa1cb623 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1370,9 +1370,15 @@ banned-module-level-imports = ["numpy", "pandas"] "airflow.AirflowException".msg = "Use airflow.exceptions.AirflowException instead." "airflow.Dataset".msg = "Use airflow.datasets.Dataset instead." "airflow.models.baseoperator.BaseOperatorLink".msg = "Use airflow.models.baseoperatorlink.BaseOperatorLink" +# Deprecated in Python 3.11, Pending Removal in Python 3.15: https://github.com/python/cpython/issues/90817 +# Deprecation warning in Python 3.11 also recommends using locale.getencoding but it available in Python 3.11 +"locale.getdefaultlocale".msg = "Use locale.setlocale() and locale.getlocale() instead." # Deprecated in Python 3.12: https://github.com/python/cpython/issues/103857 "datetime.datetime.utcnow".msg = "Use airflow.utils.timezone.utcnow or datetime.datetime.now(tz=datetime.timezone.utc)" "datetime.datetime.utcfromtimestamp".msg = "Use airflow.utils.timezone.from_timestamp or datetime.datetime.fromtimestamp(tz=datetime.timezone.utc)" +# Deprecated in Python 3.12: https://github.com/python/cpython/issues/94309 +"typing.Hashable".msg = "Use collections.abc.Hashable" +"typing.Sized".msg = "Use collections.abc.Sized" # Uses deprecated in Python 3.12 `datetime.datetime.utcfromtimestamp` "pendulum.from_timestamp".msg = "Use airflow.utils.timezone.from_timestamp"