Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions airflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 24 additions & 0 deletions newsfragments/43562.significant.rst
Original file line number Diff line number Diff line change
@@ -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
...
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 0 additions & 25 deletions tests/core/test_airflow_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down