You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/12/08 10:41:18 UTC

[GitHub] [airflow] uranusjr opened a new pull request #20131: Forward decorated function type to provide_session reusult

uranusjr opened a new pull request #20131:
URL: https://github.com/apache/airflow/pull/20131


   Now that we have `NEW_SESSION`, we don’t really need any more special hacks to make `provide_session`-decorated functions be type-checked. This is enough to type check the following:
   
   ```python
   from sqlalchemy.orm import Session
   from airflow.utils.session import NEW_SESSION, provide_session
   
   @provide_session
   def foo(x: int, *, session: Session = NEW_SESSION) -> str:
       return str(x)
   
   foo(x="a")
   foo(y=1)
   ```
   
   and emit
   
   ```
   Run mypy.................................................................Failed
   - hook id: mypy
   - exit code: 1
   
   No need to rebuild the image: none of the important files changed
   
   airflow/play.py:8: error: Argument "x" to "foo" has incompatible type "str";
   expected "int"
       foo(x="a")
             ^
   airflow/play.py:9: error: Unexpected keyword argument "y" for "foo"
       foo(y=1)
       ^
   Found 2 errors in 1 file (checked 2 source files)
   
   ERROR: The previous step completed with error. Please take a look at output above
   ```
   
   For some reason, this does not type check `session`—I can pass literally anything to it (e.g. `session=object()`) and Mypy would let it pass. Not sure why, maybe because SQLAlchemy is not well-typed? But this is still very useful.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on pull request #20131: Forward decorated function type to provide_session reusult

Posted by GitBox <gi...@apache.org>.
ashb commented on pull request #20131:
URL: https://github.com/apache/airflow/pull/20131#issuecomment-988753179


   > For some reason, this does not type check session—I can pass literally anything to it (e.g. session=object()) and Mypy would let it pass
   
   Correct. It's because our version of SQLA isn't currently typed (1.4 is) and we have `ignore_missing_imports` I think -- so `Session` is treated as `Any`, as I understand it.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #20131: Forward decorated function type to provide_session reusult

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #20131:
URL: https://github.com/apache/airflow/pull/20131#issuecomment-988729213


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #20131: Forward decorated function type to provide_session reusult

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #20131:
URL: https://github.com/apache/airflow/pull/20131#issuecomment-988728455


   Interesting, but indeed helpful :) 


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk merged pull request #20131: Forward decorated function type to provide_session reusult

Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #20131:
URL: https://github.com/apache/airflow/pull/20131


   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb edited a comment on pull request #20131: Forward decorated function type to provide_session reusult

Posted by GitBox <gi...@apache.org>.
ashb edited a comment on pull request #20131:
URL: https://github.com/apache/airflow/pull/20131#issuecomment-988753179


   > For some reason, this does not type check session—I can pass literally anything to it (e.g. session=object()) and Mypy would let it pass. Not sure why, maybe because SQLAlchemy is not well-typed?
   
   Correct. It's because our version of SQLA isn't currently typed (1.4 is) and we have `ignore_missing_imports` I think -- so `Session` is treated as `Any`, as I understand it.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org