From c3f38739dd0029f14cca3fe718d70b1ce9ca7fd5 Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Thu, 31 Oct 2024 21:25:02 +0000 Subject: [PATCH] Remove deprecated Python Version identifiers These were deprecated in 2.9 by https://github.com/apache/airflow/pull/37575 --- airflow/__init__.py | 9 --------- newsfragments/43562.significant.rst | 24 ++++++++++++++++++++++++ pyproject.toml | 7 ------- tests/core/test_airflow_module.py | 25 ------------------------- 4 files changed, 24 insertions(+), 41 deletions(-) create mode 100644 newsfragments/43562.significant.rst diff --git a/airflow/__init__.py b/airflow/__init__.py index 33005ff5e919b..411aac70fc6f7 100644 --- a/airflow/__init__.py +++ b/airflow/__init__.py @@ -100,15 +100,6 @@ def __getattr__(name: str): # PEP-562: Lazy loaded attributes on python modules module_path, attr_name, deprecated = __lazy_imports.get(name, ("", "", False)) if not module_path: - if name.startswith("PY3") and (py_minor := name[3:]) in ("6", "7", "8", "9", "10", "11", "12"): - warnings.warn( - f"Python version constraint {name!r} is deprecated and will be removed in the future. " - f"Please get version info from the 'sys.version_info'.", - DeprecationWarning, - stacklevel=2, - ) - return sys.version_info >= (3, int(py_minor)) - raise AttributeError(f"module {__name__!r} has no attribute {name!r}") elif deprecated: warnings.warn( diff --git a/newsfragments/43562.significant.rst b/newsfragments/43562.significant.rst new file mode 100644 index 0000000000000..4e50fa609da21 --- /dev/null +++ b/newsfragments/43562.significant.rst @@ -0,0 +1,24 @@ +Removed Deprecated Python Version Identifiers from the ``airflow`` Module + +Python version check constants, such as ``PY36``, ``PY37``, and others, have been removed from the ``airflow`` +module. To check Python versions, please use the ``sys.version_info`` attribute directly instead. + +Before: + +.. code-block:: python + + from airflow import PY36 + + if PY36: + # perform some action + ... + +After: + +.. code-block:: python + + import sys + + if sys.version_info >= (3, 6): + # perform some action + ... diff --git a/pyproject.toml b/pyproject.toml index 1ed9136da3f9a..6e9c3a6f9718b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -410,13 +410,6 @@ banned-module-level-imports = ["numpy", "pandas"] # Direct import from the airflow package modules and constraints "airflow.AirflowException".msg = "Use airflow.exceptions.AirflowException instead." "airflow.Dataset".msg = "Use airflow.datasets.Dataset instead." -"airflow.PY36".msg = "Use sys.version_info >= (3, 6) instead." -"airflow.PY37".msg = "Use sys.version_info >= (3, 7) instead." -"airflow.PY38".msg = "Use sys.version_info >= (3, 8) instead." -"airflow.PY39".msg = "Use sys.version_info >= (3, 9) instead." -"airflow.PY310".msg = "Use sys.version_info >= (3, 10) instead." -"airflow.PY311".msg = "Use sys.version_info >= (3, 11) instead." -"airflow.PY312".msg = "Use sys.version_info >= (3, 12) instead." # Deprecated imports "airflow.models.baseoperator.BaseOperatorLink".msg = "Use airflow.models.baseoperatorlink.BaseOperatorLink" "airflow.models.errors.ImportError".msg = "Use airflow.models.errors.ParseImportError" diff --git a/tests/core/test_airflow_module.py b/tests/core/test_airflow_module.py index d448f4bc93f70..f06c5487cd993 100644 --- a/tests/core/test_airflow_module.py +++ b/tests/core/test_airflow_module.py @@ -16,36 +16,11 @@ # under the License. from __future__ import annotations -import sys - import pytest import airflow from airflow.exceptions import AirflowException -TEST_CASES = { - "PY36": sys.version_info >= (3, 6), - "PY37": sys.version_info >= (3, 7), - "PY38": sys.version_info >= (3, 8), - "PY39": sys.version_info >= (3, 9), - "PY310": sys.version_info >= (3, 10), - "PY311": sys.version_info >= (3, 11), - "PY312": sys.version_info >= (3, 12), -} - - -@pytest.mark.parametrize("py_attr, expected", TEST_CASES.items()) -def test_lazy_load_py_versions(py_attr, expected): - with pytest.warns(DeprecationWarning, match=f"Python version constraint '{py_attr}' is deprecated"): - # If there is no warning, then most possible it imported somewhere else. - assert getattr(airflow, py_attr) is expected - - -@pytest.mark.parametrize("py_attr", ["PY35", "PY313"]) -def test_wrong_py_version(py_attr): - with pytest.raises(AttributeError, match=f"'airflow' has no attribute '{py_attr}'"): - getattr(airflow, py_attr) - def test_deprecated_exception(): warning_pattern = "Import 'AirflowException' directly from the airflow module is deprecated"