-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Fix MyPy errors in Apache Providers #20422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
cc: @khalidmammadov |
|
If we agree this is the right way of treating context we could easily automate and apply it to all operators/sensors that have currnetly: or as a single big change (after we complete all other MyPy changes. WDYT? |
|
|
And including airlfow built-ins (there we could directly import airflow's context): |
airflow/providers/apache/cassandra/example_dags/example_cassandra_dag.py
Outdated
Show resolved
Hide resolved
74d37c9 to
bff4438
Compare
bff4438 to
723a882
Compare
723a882 to
7c1c7bf
Compare
|
I am afraid I have no better idea for the "Context" imports from providers though :( |
|
Need some review here - anyone has better idea what to do instead of: I would like to automatically add it later to all the provider's executes/pokes to really benefit from the latest TypeDict Context improvements :D, but maybe we can find a better way ? The problem with it is we can't rely on the common code in airflow :( |
|
Hi Jarek,
Since typing is not required for runtime, I have amended it to just below.
|if TYPE_CHECKING: from airflow.utils.context import Context|
Is that OK?
- Did the same in #20409
…On 21/12/2021 13:13, Jarek Potiuk wrote:
Need some review here - anyone has better idea what to do instead of:
|if TYPE_CHECKING: from airflow.utils.context import Context else:
Context = MutableMapping[str, Any] |
I would like to automatically add it later to all the provider's
executes/pokes to really benefit from the latest TypeDict Context
improvements :D, but maybe we can find a better way ? The problem with
it is we can't rely on the common code in airflow :(
—
Reply to this email directly, view it on GitHub
<#20422 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACYJ3NFYVTDOCSBORMHASA3USB4OLANCNFSM5KNYLA4A>.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Ignore me, we still need that part
…On 21/12/2021 21:34, Khalid Mammadov wrote:
Hi Jarek,
Since typing is not required for runtime, I have amended it to just
below.
|if TYPE_CHECKING: from airflow.utils.context import Context|
Is that OK?
- Did the same in #20409
On 21/12/2021 13:13, Jarek Potiuk wrote:
>
> Need some review here - anyone has better idea what to do instead of:
>
> |if TYPE_CHECKING: from airflow.utils.context import Context else:
> Context = MutableMapping[str, Any] |
>
> I would like to automatically add it later to all the provider's
> executes/pokes to really benefit from the latest TypeDict Context
> improvements :D, but maybe we can find a better way ? The problem
> with it is we can't rely on the common code in airflow :(
>
> —
> Reply to this email directly, view it on GitHub
> <#20422 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACYJ3NFYVTDOCSBORMHASA3USB4OLANCNFSM5KNYLA4A>.
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
Nice try though :) |
7c1c7bf to
0f90cde
Compare
|
I don’t think we need the if TYPE_CHECKING:
from airflow.utils.context import Context
def execute(self, context: "Context") -> None:
... |
I can confirm this works in #20034 for the Docker decorator. |
|
Ah yeah! good one @uranusjr . I totally forgot that we can quote context :) |
|
That's why I was waiting with applying that. Now we can actually even make it truly "one-liner - cc: @khalidmammadov : (not sure if black will be happy with it though) |
|
Black is not happy with one-liner :( |
0f90cde to
38df9d1
Compare
|
All should be nicely updaated. @uranusjr - good stuff with the "Context" |
38df9d1 to
7984d61
Compare
|
Should be good to go and I'd love t refresh stats after that :) |
|
It seems I’m missing context on the pyi additions. |
|
Looking at airflow/utils. Let me know if you as well |
afcbefd to
8a6e6bc
Compare
Context added. |
1 similar comment
Context added. |
Part of apache#19891 The .pyi additions are to handle "default_args" passed in examples. Currently some of the obligatory parameters are (correctly) passed as default_args. We have no good mechanism yet to handle it properly for MyPy (it would require to add a custom MyPy plugin to handle it) We have no better way to handle it for now.
8a6e6bc to
2e90189
Compare
|
Can I get the approval :) ? MyPy is calling. |
|
The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease. |
Part of #19891
The .py additions are to handle "default_args" passed in
examples. Currently some of the obligatory parameters are
(correctly) passed as default_args. We have no good
mechanism yet to handle it properly for MyPy (it would
require to add a custom MyPy plugin to handle it)
We have no better way to handle it for now.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.