sunank200 commented on code in PR #51153:
URL: https://github.com/apache/airflow/pull/51153#discussion_r2123472133


##########
task-sdk/src/airflow/sdk/__init__.py:
##########
@@ -126,3 +132,8 @@ def __getattr__(name: str):
         globals()[name] = val
         return val
     raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
+
+def __dir__() -> list[str]:
+    """Override dir() to expose only the public API names and internal 
attributes."""
+    return sorted(__all__ + ["__getattr__", "__lazy_imports"])

Review Comment:
   `from airflow.sdk import *” only determines what is imported and does not 
affect what `dir()` displays. By default, `dir(module)` lists items in 
`module.__dict__`, not what is in `all`. With lazy loading, lazy names are not 
in `__dict__` until imported, which disrupts tooling that relies on `dir()` to 
discover APIs.
   
   To fix this, I have overridden `dir` to include `sorted(all + ["getattr", 
"__lazy_imports"])`, so users see the complete public API immediately. 



##########
task-sdk/src/airflow/sdk/__init__.py:
##########
@@ -126,3 +132,8 @@ def __getattr__(name: str):
         globals()[name] = val
         return val
     raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
+
+def __dir__() -> list[str]:
+    """Override dir() to expose only the public API names and internal 
attributes."""
+    return sorted(__all__ + ["__getattr__", "__lazy_imports"])

Review Comment:
   `from airflow.sdk import *` only determines what is imported and does not 
affect what `dir()` displays. By default, `dir(module)` lists items in 
`module.__dict__`, not what is in `all`. With lazy loading, lazy names are not 
in `__dict__` until imported, which disrupts tooling that relies on `dir()` to 
discover APIs.
   
   To fix this, I have overridden `dir` to include `sorted(all + ["getattr", 
"__lazy_imports"])`, so users see the complete public API immediately. 



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