ferruzzi commented on code in PR #22862:
URL: https://github.com/apache/airflow/pull/22862#discussion_r846285920


##########
airflow/__init__.py:
##########
@@ -54,18 +54,31 @@
 PY39 = sys.version_info >= (3, 9)
 PY310 = sys.version_info >= (3, 10)
 
+# Things to lazy import in form 'name': 'path.to.module'
+__lazy_imports = {
+    'DAG': 'airflow.models.dag',
+    'XComArg': 'airflow.models.xcom_arg',
+    'AirflowException': 'airflow.exceptions',
+}
+
 
 def __getattr__(name):
     # PEP-562: Lazy loaded attributes on python modules
-    if name == "DAG":
-        from airflow.models.dag import DAG
+    path = __lazy_imports.get(name)
+    if not path:
+        raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
+    import operator
 
-        return DAG
-    if name == "AirflowException":
-        from airflow.exceptions import AirflowException
+    # Strip of the "airflow." prefix because of how `__import__` works (it 
always returns the top level

Review Comment:
   ```suggestion
       # Strip off the "airflow." prefix because of how `__import__` works (it 
always returns the top level
   ```



-- 
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]

Reply via email to