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/01 21:40:14 UTC
[GitHub] [airflow] josh-fell commented on a change in pull request #19918: Fix mypy errors in example DAGs
josh-fell commented on a change in pull request #19918:
URL: https://github.com/apache/airflow/pull/19918#discussion_r760591039
##########
File path: airflow/providers/alibaba/cloud/example_dags/example_oss_bucket.py
##########
@@ -14,6 +14,10 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+
+# Ignore mypy argument checking. Some operator args will be passed via ``default_args``.
+# type: ignore[call-arg]
Review comment:
@ashb Thanks for pro tip!
A little confused though and probably a dumb question coming: The `@task` decorator doesn't apply in these example DAGs. Is this more related to `BaseOperator`? This is my first real foray into mypy madness so just trying to getting my bearings on a fix.
But If we did start adding type annotations on TaskFlow functions in example DAGs, mypy probably wouldn't complain during its arg checking, right? We'll have to set a default value for the arg in the function signature to avoid a `TypeError` when parsing the DAG in order to use `default_args` (as we would if we wanted to directly access `context` fields).
Mypy is quiet on something like this:
```python
from datetime import datetime
from typing import Dict, Optional
from airflow.decorators import dag, task
@task
def blah(stuff: Optional[str] = None, other_stuff: str = "Nope."):
print(stuff)
print(other_stuff)
@dag(
start_date=datetime(2021, 12, 1),
schedule_interval=None,
default_args={"stuff": "Here is your stuff.", "other_stuff": "Mine."},
)
def blah_blah():
_blah = blah()
dag = blah_blah()
```
--
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