Taragolis commented on code in PR #34541:
URL: https://github.com/apache/airflow/pull/34541#discussion_r1334834399
##########
airflow/__init__.py:
##########
@@ -76,21 +76,31 @@
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,
Review Comment:
I required to import from airflow.exceptions module 🙂, which might be a
reason for circular import.
I guess for the same reason we do not use internal warning in
airflow.configuration and use generic one
##########
airflow/__init__.py:
##########
@@ -76,21 +76,31 @@
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,
Review Comment:
I required to import from airflow.exceptions module 🙂, which might be a
reason for circular import.
I guess for the same reason we do not use internal warning in
airflow.configuration and use generic one
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]