Skip to content
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

Fix mypy providers #20190

Merged
merged 35 commits into from
Dec 15, 2021
Merged

Fix mypy providers #20190

merged 35 commits into from
Dec 15, 2021

Conversation

subkanthi
Copy link
Contributor

@subkanthi subkanthi commented Dec 10, 2021

Fixes mypy in

  • airflow/providers/apache/spark/hooks
  • airflow/providers/jira
  • airflow/providers/apache/cassandra/example_dags
  • airflow/providers/telegram
  • airflow/providers/asana
  • airflow/providers/trino/hooks
  • airflow/providers/postgres
  • airflow/providers/slack
  • airflow/providers/trino

related: #19891


^ 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.

@subkanthi subkanthi marked this pull request as draft December 10, 2021 04:17
@subkanthi subkanthi mentioned this pull request Dec 10, 2021
10 tasks
@subkanthi subkanthi marked this pull request as ready for review December 10, 2021 18:52
airflow/providers/asana/example_dags/example_asana.py Outdated Show resolved Hide resolved
airflow/providers/asana/hooks/asana.py Outdated Show resolved Hide resolved

try:
conn: "Optional[Connection]" = self.get_connection(conn_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the stringified typing can safely be removed then the TYPE_CHECKING statement can also be removed. You'll need to confirm though with some testing. MyPy should complain if it's an issue.

@kaxil @potiuk Another example of get_connection() in a hook's __init__() here. Oddly enough, this hook has a get_conn() method but it's a null method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think this is going to work at runtime. The stringified version is still needed.

Copy link
Member

@potiuk potiuk Dec 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm @josh-fell (and @kaxil ) - Something struck, me I just looked closer at the #18339

I think while discussing it I made a silent assumption (which I see now was wrong ) that the connection was created as part of "operator's" init but this is about creating it in the Hook's init, which IMHO is quite legitimate use case (as long as you do not instantiate the Hook in the operator's init(). And it is pretty common pattern in Airflow (and one we actually encourage).

I double-checked and I looked at the Databricks code and the only place I could see it being instantiated was _get_hook() and the only place where _get_hook() is called was inside "execute" and "on_kill" method of the Databricks operator - so that all sounds pretty legitimate.

Was not the whole issue caused by a misunderstanding of who's init it was? I think we have maaaaany cases where Hook is created "on-demand" in execute() method of the operator, also if you decide to create the Hook() inside the @task-decorated functions, it should work really well.
Are my eyes cheating me ? O r maybe I miss something?

@subkanthi subkanthi requested review from potiuk and uranusjr December 12, 2021 00:45
@potiuk potiuk added the mypy Fixing MyPy problems after bumpin MyPy to 0.990 label Dec 13, 2021
@potiuk
Copy link
Member

potiuk commented Dec 14, 2021

Conflict to solve, I am afraid @subkanthi :(

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Dec 14, 2021
@github-actions
Copy link

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.

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coudl you please remove the docker change and rebase?

@subkanthi subkanthi requested a review from potiuk December 14, 2021 17:49
@uranusjr uranusjr merged commit dad2f81 into apache:main Dec 15, 2021
@kaxil kaxil added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) mypy Fixing MyPy problems after bumpin MyPy to 0.990 okay to merge It's ok to merge this PR as it does not require more tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants