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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to