techalchemy commented on a change in pull request #4685: [AIRFLOW-3862] Check 
types with mypy.
URL: https://github.com/apache/airflow/pull/4685#discussion_r257390078
 
 

 ##########
 File path: setup.py
 ##########
 @@ -319,6 +318,7 @@ def do_setup():
             'sqlalchemy>=1.1.15, <1.3.0',
             'tabulate>=0.7.5, <=0.8.2',
             'tenacity==4.12.0',
+            'typing',
 
 Review comment:
   hey, random stranger here -- I found this issue because I was trying to 
typecheck my own airflow implementation and found that airflow itself doesn't 
have published stubs, so that caused some issues.  Just wanted to chime in and 
say that type checking actually can be pretty slow, which is why python 3.7 
even introduced a `__future__` import to perform lazy typechecking imports.  
See [PEP 563](https://www.python.org/dev/peps/pep-0563) for reference.
   
   What's more, you can't put typechecking imports behind a conditional unless 
you actually have `typing` installed in the first place to check whether the 
typechecker is running.  The conventional approach is to just use 
`'typing;python_version<"3.5"'` as your constraint.
   
   The alternative approach is to do this (I actually do both personally but in 
theory you can pick one):
   
   ```python
   def is_type_checking():
       try:
           from typing import TYPE_CHECKING
       except ImportError:
           return False
       return TYPE_CHECKING
   
   MYPY_RUNNING = is_type_checking()
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to