Skip to content

Move type-only third-party imports under TYPE_CHECKING in providers#67590

Open
omkar-334 wants to merge 3 commits into
apache:mainfrom
omkar-334:type-checking-fix
Open

Move type-only third-party imports under TYPE_CHECKING in providers#67590
omkar-334 wants to merge 3 commits into
apache:mainfrom
omkar-334:type-checking-fix

Conversation

@omkar-334
Copy link
Copy Markdown

Third-party names that are only used in type annotations. Every file in this PR already has from __future__ import annotations, so those annotations are stored as strings at runtime. The imports never need to be in sys.modules to make the code work; they only need to be resolvable for static analysis. No runtime imports were moved inline

Related issue - #67515, #67519 (comment)

Each change is the same shape:

-from third_party import RuntimeName, TypeOnlyName
+from third_party import RuntimeName

 if TYPE_CHECKING:
+    from third_party import TypeOnlyName

How candidates were picked

A small AST pass over providers/*/src flagged top-level third-party imports whose every reference falls in an annotation position (function args, returns, AnnAssign).


Was generative AI tooling used to co-author this PR?

@boring-cyborg
Copy link
Copy Markdown

boring-cyborg Bot commented May 27, 2026

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@omkar-334 omkar-334 force-pushed the type-checking-fix branch from a714401 to c82d372 Compare May 27, 2026 07:25
@omkar-334 omkar-334 requested a review from shahar1 as a code owner May 27, 2026 07:25
from airflow.utils.log.logging_mixin import LoggingMixin

if TYPE_CHECKING:
from alibabacloud_adb20211201.models import SubmitSparkAppResponse
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, not this of a change. What I meant is move imports where the module hasn't already been imported.

In this case alibabacloud_adb20211201.models is already imported on L26, so this change won't have any impact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants