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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]