amoghrajesh commented on PR #60676:
URL: https://github.com/apache/airflow/pull/60676#issuecomment-3763130335

   @ashb thanks for your review, I handled the `import airflow.x` type imports. 
As for method scoped imports, those will be caught by the script because we use 
`ast.walk(tree)` to walk through all nodes of the tree: 
https://docs.python.org/3/library/ast.html#ast.walk
   
   Ran it by an example:
   ```shell
   (apache-airflow) ➜  airflow git:(prek-hook-to-check-core-imports) ✗ cat 
/tmp/examples.py                                     
   from airflow.sdk import Connection
   
   def my_function():
       from airflow.models import DagRun
       import airflow.triggers.base
       
       from airflow.sdk.types import RuntimeTaskInstance
       
   def another_function():
       if True:
           from airflow.serialization import serialize
           
   class MyClass:
       def method(self):
           import airflow.dag_processing
   (apache-airflow) ➜  airflow git:(prek-hook-to-check-core-imports) ✗ python 
scripts/ci/prek/check_core_imports_in_sdk.py /tmp/examples.py
   /tmp/examples.py:
     Line 4: from airflow.models import DagRun
     Line 5: import airflow.triggers.base
     Line 11: from airflow.serialization import serialize
     Line 15: import airflow.dag_processing
   
   Found 4 core import(s) in task-sdk files
   
   ```


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