You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "benbuckman (via GitHub)" <gi...@apache.org> on 2023/07/05 21:02:38 UTC
[GitHub] [airflow] benbuckman opened a new issue, #32384: Type annotation for `@task` errors when called with parentheses/arguments
benbuckman opened a new issue, #32384:
URL: https://github.com/apache/airflow/issues/32384
### Apache Airflow version
2.6.2
### What happened
👋 If I define a task with `@task` (via `from airflow.decorators import task`) then mypy (type checker) is happy. If I add add parentheses to add arguments, like `@task()` or `@task(queue='foo')`, then mypy complains,
```
Untyped decorator makes function [name] untyped.
```
I see in airflow src, there are [example DAGs](https://github.com/apache/airflow/blob/2.6.2/airflow/example_dags/tutorial_taskflow_api_virtualenv.py/#L59) with `@task()` (using parentheses). So I also wonder how this works internally.
Thank you!
### What you think should happen instead
Mypy should understand both,
```python
@task
def foo():
...
```
and
```python
@task()
def foo():
...
```
and
```python
@task(queue='secondary')
def foo():
...
```
### How to reproduce
- Python 3.10.8
- Airflow 2.6.2
- Mypy 1.0.0 (as defined by [constraints file](https://raw.githubusercontent.com/apache/airflow/constraints-2.6.2/constraints-3.10.txt)
- (Note: upgrading mypy to the latest 1.4.1 results in the same behavior.)
Place somewhere in `{dags_folder}`:
```python
from datetime import datetime
from airflow.decorators import dag, task
@task
def task_without_parens_is_fine() -> None:
...
@task()
# ^ type error on this line: "Untyped decorator makes function "demo_type_error" untyped"
def demo_type_error() -> None:
...
@dag(schedule=None, start_date=datetime(2021, 1, 1), catchup=False)
def demo_dag():
demo_type_error()
demo_dag()
```
Run `mypy .` in the parent or application-root folder.
### Operating System
MacOS Ventura 13.4
### Versions of Apache Airflow Providers
apache-airflow-providers-common-sql==1.5.1
apache-airflow-providers-ftp==3.4.1
apache-airflow-providers-google==10.1.1
apache-airflow-providers-http==4.4.1
apache-airflow-providers-imap==3.2.1
apache-airflow-providers-postgres==5.5.0
apache-airflow-providers-sendgrid==3.2.0
apache-airflow-providers-slack==7.3.0
apache-airflow-providers-sqlite==3.4.1
### Deployment
Official Apache Airflow Helm Chart
### Deployment details
The deployment is not relevant to this issue, as this can be reproduced locally in a mypy-enabled IDE or in a terminal running `mypy <dir>`.
### Anything else
I tried to copy/use the [`dev/mypy/plugins/decorators.py`](https://github.com/apache/airflow/blob/2.6.2/dev/mypy/plugin/decorators.py/#L35) mypy plugin in my application, but this did not help. (And anyway that file is not exported in the public `apache-airflow` package.)
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on issue #32384: Type annotation for `@task` errors when called with parentheses/arguments
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on issue #32384:
URL: https://github.com/apache/airflow/issues/32384#issuecomment-1622503591
Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.
--
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 issue #32384: Type annotation for `@task` errors when called with parentheses/arguments
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on issue #32384:
URL: https://github.com/apache/airflow/issues/32384#issuecomment-1627473702
Feel free. Not sure if this is absolutely necessary but if it can be improved, this is cool.
--
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] benbuckman commented on issue #32384: Type annotation for `@task` errors when called with parentheses/arguments
Posted by "benbuckman (via GitHub)" <gi...@apache.org>.
benbuckman commented on issue #32384:
URL: https://github.com/apache/airflow/issues/32384#issuecomment-1623831755
mypy needs `--strict` mode to see this:
host:
```
$ docker run -it --rm apache/airflow:2.6.2-python3.10 bash
```
container:
```
$ pip install 'mypy==1.0.0'
$ printf 'from datetime import datetime
from airflow.decorators import dag, task
@task()
def demo_type_error() -> None:
...
@dag(schedule=None, start_date=datetime(2021, 1, 1), catchup=False)
def demo_dag() -> None:
demo_type_error()
demo_dag()' > /opt/airflow/dags/t.py
$ cd dags
# (this takes a while to build the cache the first time)
$ mypy --strict .
```
I see:
```
t.py:7: error: Untyped decorator makes function "demo_type_error" untyped [misc]
Found 1 error in 1 file (checked 1 source file)
```
--
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
Re: [I] Type annotation for `@task` errors when called with parentheses/arguments [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #32384:
URL: https://github.com/apache/airflow/issues/32384#issuecomment-2254368577
This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.
--
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] uranusjr commented on issue #32384: Type annotation for `@task` errors when called with parentheses/arguments
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on issue #32384:
URL: https://github.com/apache/airflow/issues/32384#issuecomment-1623360589
Hmm, I can’t reproduce with a clean environment:
```console
$ docker run -iqt --rm apache/airflow:2.6.2 bash
airflow@d1644eaceff2:/opt/airflow$ pip install mypy -q
airflow@d1644eaceff2:/opt/airflow$ printf 'from airflow.decorators import dag, task
@task
def task_without_parens_is_fine() -> None:
...
@task()
def demo_type_error() -> None:
...
' > /opt/airflow/dags/t.py
airflow@d1644eaceff2:/opt/airflow$ cd dags
airflow@d1644eaceff2:/opt/airflow$ cat t.py
from airflow.decorators import dag, task
@task
def task_without_parens_is_fine() -> None:
...
@task()
def demo_type_error() -> None:
...
airflow@d1644eaceff2:/opt/airflow$ mypy t.py
Success: no issues found in 1 source file
```
--
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] kelechi2020 commented on issue #32384: Type annotation for `@task` errors when called with parentheses/arguments
Posted by "kelechi2020 (via GitHub)" <gi...@apache.org>.
kelechi2020 commented on issue #32384:
URL: https://github.com/apache/airflow/issues/32384#issuecomment-1627380690
@potiuk I want to work on this.
--
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
Re: [I] Type annotation for `@task` errors when called with parentheses/arguments [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #32384:
URL: https://github.com/apache/airflow/issues/32384#issuecomment-2322788756
This issue has been closed because it has not received response from the issue author.
--
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
Re: [I] Type annotation for `@task` errors when called with parentheses/arguments [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed issue #32384: Type annotation for `@task` errors when called with parentheses/arguments
URL: https://github.com/apache/airflow/issues/32384
--
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