vincbeck commented on code in PR #28900:
URL: https://github.com/apache/airflow/pull/28900#discussion_r1309045128
##########
airflow/models/taskinstance.py:
##########
@@ -371,6 +373,802 @@ def _creator_note(val):
return TaskInstanceNote(*val)
+def _execute_task(task_instance, context, task_orig):
Review Comment:
Doing this makes mypy-core very angry. I remembered trying to solve the
issues but then I gave up because I was going in a rabbit hole. The issue is by
adding type annotation you get issues that exist today in the code but are not
surfaced because there is no type annotation. Errors returned by mypy-core:
```
airflow/models/taskinstance.py:404: error: Incompatible types in assignment
(expression has type "Callable[[Context], Any]", variable has type
"Callable[[str, Optional[Dict[str, Any]], Context], Any]") [assignment]
execute_callable = task_to_execute.execute
^~~~~~~~~~~~~~~~~~~~~~~
airflow/models/taskinstance.py:412: error: No overload variant of "__sub__"
of
"datetime" matches argument type "None" [operator]
... task_to_execute.execution_timeout - (timezone.utcnow() -
t...
^~~~~~~~~~~~~~~~~~~~~...
airflow/models/taskinstance.py:412: note: Possible overload variants:
airflow/models/taskinstance.py:412: note: def __sub__(self, timedelta,
/) -> datetime
airflow/models/taskinstance.py:412: note: def __sub__(self, datetime, /)
-> timedelta
airflow/models/taskinstance.py:412: note: Right operand is of type
"Union[Any, datetime, None]"
airflow/models/taskinstance.py:422: error: Argument 2 has incompatible type
"**Dict[str, Union[Any, str]]"; expected "Optional[Dict[str, Any]]"
[arg-type]
... result = execute_callable(context=context,
**execute_callable_kwar...
^~~~~~~~~~~~~~~~~~~~~~~
airflow/models/taskinstance.py:422: note: "Dict" is invariant -- see
https://mypy.readthedocs.io/en/stable/common_issues.html#variance
airflow/models/taskinstance.py:422: note: Consider using "Mapping" instead,
which is covariant in the value type
airflow/models/taskinstance.py:427: error: Argument 2 has incompatible type
"**Dict[str, Union[Any, str]]"; expected "Optional[Dict[str, Any]]"
[arg-type]
... result = execute_callable(context=context,
**execute_callable_kwar...
^~~~~~~~~~~~~~~~~~~~~~~
airflow/models/taskinstance.py:427: note: "Dict" is invariant -- see
https://mypy.readthedocs.io/en/stable/common_issues.html#variance
airflow/models/taskinstance.py:427: note: Consider using "Mapping" instead,
which is covariant in the value type
```
I feel like we might want to solve these issues in a separate PR because
these issues exist today, it is not coming from this PR
--
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]