This is an automated email from the ASF dual-hosted git repository.

vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 7764a51ac9 Deprecate lazy import `AirflowException` from airflow 
(#34541)
7764a51ac9 is described below

commit 7764a51ac9b021a77a57707bc7e750168e9e0da0
Author: Andrey Anshin <[email protected]>
AuthorDate: Fri Oct 6 18:33:09 2023 +0400

    Deprecate lazy import `AirflowException` from airflow (#34541)
---
 airflow/__init__.py | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/airflow/__init__.py b/airflow/__init__.py
index 42a50aa02c..b63ff1dc05 100644
--- a/airflow/__init__.py
+++ b/airflow/__init__.py
@@ -76,21 +76,31 @@ PY39 = sys.version_info >= (3, 9)
 PY310 = sys.version_info >= (3, 10)
 PY311 = sys.version_info >= (3, 11)
 
-# Things to lazy import in form {local_name: ('target_module', 'target_name')}
-__lazy_imports: dict[str, tuple[str, str]] = {
-    "DAG": (".models.dag", "DAG"),
-    "Dataset": (".datasets", "Dataset"),
-    "XComArg": (".models.xcom_arg", "XComArg"),
-    "AirflowException": (".exceptions", "AirflowException"),
-    "version": (".version", ""),
+# Things to lazy import in form {local_name: ('target_module', 'target_name', 
'deprecated')}
+__lazy_imports: dict[str, tuple[str, str, bool]] = {
+    "DAG": (".models.dag", "DAG", False),
+    "Dataset": (".datasets", "Dataset", False),
+    "XComArg": (".models.xcom_arg", "XComArg", False),
+    "version": (".version", "", False),
+    # Deprecated lazy imports
+    "AirflowException": (".exceptions", "AirflowException", True),
 }
 
 
 def __getattr__(name: str):
     # PEP-562: Lazy loaded attributes on python modules
-    module_path, attr_name = __lazy_imports.get(name, ("", ""))
+    module_path, attr_name, deprecated = __lazy_imports.get(name, ("", "", 
False))
     if not module_path:
         raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+    elif deprecated:
+        import warnings
+
+        warnings.warn(
+            f"Import {name!r} directly from the airflow module is deprecated 
and "
+            f"will be removed in the future. Please import it from 
'airflow{module_path}.{attr_name}'.",
+            DeprecationWarning,
+            stacklevel=2,
+        )
 
     import importlib
 

Reply via email to