potiuk edited a comment on issue #7007: [AIRFLOW-6428] Add dates module to 
airflow/utils/__init__.py
URL: https://github.com/apache/airflow/pull/7007#issuecomment-570373212
 
 
   Why don't we do it "differently" ... 
   
   I am not sure why we are using those imports in this form? Do we have 
something that holds us back from changing all "days_ago" imports to the form 
that is much more pythonic (IMHO)? 
   
   Adding anything to `__init__.py` inside the application creates unnecessary 
dependencies. Anybody using "airflow.utils.somethingelse" will add an implicit 
dependency to "airflow.utils.dates" if we add dates to `__init__.py` even if it 
is not used . This adds unnecessary dependencies (and leads to circular 
dependencies).
   
   I think most of our __init__.py should be empty (or removed  if we go to 
implicit python3 packages). I believe adding anything to __init__.py makes only 
sense if we provide a reusable library. with one package structure - where if 
you import it, you should have access to all exposed functions. I am happy to 
discuss it though, as we might have different understanding - and maybe we 
should expose all "exposable" classes from unit in this way as part of the 
"official airflow interface" (but I still think import should be `from 
airflow.utils.xxx import yyy` anyway).
   
   Just to summary - we have two options:
   
   1. Import airflow and then rely on the __init__ packages
   ```
   import airflow
   ```
   and then using
   ```
   airflow.utils.dates.days_ago(2)
   ```
   
   2. Import the function directly (much better IMHO).
   
   ```
   from airflow.utils.dates import days_ago
   ```
   
   Option 1 (with importing the whole 'airflow').
   
   <img width="486" alt="Screenshot 2020-01-02 at 23 16 23" 
src="https://user-images.githubusercontent.com/595491/71696745-13efc580-2db6-11ea-855c-25ca7901ff49.png";>
   
   Option 2: (wiht importing only the function we need)
   
   <img width="489" alt="Screenshot 2020-01-02 at 23 09 14" 
src="https://user-images.githubusercontent.com/595491/71696484-5d8be080-2db5-11ea-8403-49a845a25510.png";>
   
   WDYT @kaxil?
   
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to