Skip to content

[airflow] Extract common utilities for use in new rules#23630

Merged
amyreese merged 1 commit intoastral-sh:mainfrom
Dev-iL:2602/airflow/utils
Mar 3, 2026
Merged

[airflow] Extract common utilities for use in new rules#23630
amyreese merged 1 commit intoastral-sh:mainfrom
Dev-iL:2602/airflow/utils

Conversation

@Dev-iL
Copy link
Copy Markdown
Contributor

@Dev-iL Dev-iL commented Feb 28, 2026

Summary

Extract is_airflow_task and in_airflow_task_function from removal_in_3.rs (AIR301) into the shared helpers.rs module so they can be reused by other airflow rules.

The shared versions include two enhancements over the original private implementations:

  • Match both airflow.decorators.task and airflow.sdk.task import paths, supporting Airflow 2 and 3 decorator imports.
  • Handle @task.<variant> decorator forms (e.g., @task.branch, @task.short_circuit), not just @task and @task().

Test Plan

Added airflow.sdk test cases to AIR301_context.py confirming that deprecated context key detection works under both @task (from airflow.decorators) and @sdk_task (from airflow.sdk). Existing AIR301 tests continue to pass.

RUFF_UPDATE_SCHEMA=1 cargo nextest run -p ruff_linter -- "airflow::tests"
cargo clippy -p ruff_linter --all-targets --all-features -- -D warnings

Related: #23579 #23584

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Feb 28, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@amyreese amyreese added the internal An internal refactor or improvement label Mar 2, 2026
@amyreese
Copy link
Copy Markdown
Contributor

amyreese commented Mar 2, 2026

Is this an expansion of what AIR301 catches, or just new test cases covering existing behavior?

@Dev-iL
Copy link
Copy Markdown
Contributor Author

Dev-iL commented Mar 2, 2026

Is this an expansion of what AIR301 catches, or just new test cases covering existing behavior?

Yes, the rule is changed by this, but this is more of a byproduct of the refactor. In theory, AIR301 becomes more comprehensive in catching deprecated patterns across different Airflow versions. In practice however, I would expect to see new hits in the ecosystem scan of the airflow codebase - which is not the case.

Comment thread crates/ruff_linter/src/rules/airflow/helpers.rs
Comment thread crates/ruff_linter/src/rules/airflow/helpers.rs Outdated
Move these decorator-checking functions from removal_in_3.rs (AIR301)
to helpers.rs so they can be reused by other airflow rules. The shared
versions now also match the airflow.sdk.task import path and handle
@task.<variant> forms (e.g., @task.branch, @task.short_circuit),
ensuring AIR301 context checks work for both Airflow 2 and 3 decorator
imports.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Dev-iL Dev-iL force-pushed the 2602/airflow/utils branch from 29ab30f to 4bdbfcb Compare March 3, 2026 06:18
@Dev-iL Dev-iL requested a review from amyreese March 3, 2026 06:20
@amyreese amyreese added the rule Implementing or modifying a lint rule label Mar 3, 2026
@amyreese amyreese merged commit f8d1d29 into astral-sh:main Mar 3, 2026
44 checks passed
@Dev-iL Dev-iL deleted the 2602/airflow/utils branch March 3, 2026 20:21
carljm added a commit that referenced this pull request Mar 16, 2026
* main:
  [ty] Split up `types/class.rs` (#23714)
  [ty] Rework module resolution to be breadth-first instead of depth-first (#22449)
  [ty] Move tests and type-alias-related code out of `types.rs` (#23711)
  [ty] Move TypeVar-related code to a `types::typevar` submodule (#23710)
  Fail CI on new linter ecosystem panics (#23597)
  [ty] Fix handling of non-Python text documents
  [ty] Move `CallableType`, and related methods/types, to a new `types::callable` submodule (#23707)
  [ty] Avoid stack overflow with recursive typevar (#23652)
  [ty] Add a diagnostic for an unused awaitable (#23650)
  [ty] Fix union `*args` binding for optional positional parameters (#23124)
  [`refurb`] Fix `FURB101` and `FURB103` false positives when I/O variable is used later (#23542)
  [ty] Fix type checking for multi-member enums within in a function block (#23683)
  [ty] Improve folding for decorators (#23543)
  [`airflow`] Extract common utilities for use in new rules (#23630)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants