Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Open
Dev-iL wants to merge 1 commit intoastral-sh:mainfrom
Dev-iL:2602/airflow/utils
Open

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

Conversation

@Dev-iL
Copy link
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

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 a786ed8 to 29ab30f Compare February 28, 2026 08:01
@astral-sh-bot
Copy link

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
Member

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
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 on lines +310 to +315
// Match `@task.<variant>` (e.g., `@task.branch`, `@task.short_circuit`).
if let Expr::Attribute(ExprAttribute { value, .. }) = expr {
return semantic.resolve_qualified_name(value).is_some_and(|qn| {
matches!(qn.segments(), ["airflow", "decorators" | "sdk", "task"])
});
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test case exercising this?

Comment on lines +321 to +328
/// Returns `true` if the current statement hierarchy has a function that's decorated with
/// `@airflow.decorators.task` or `@airflow.sdk.task`.
pub(crate) fn in_airflow_task_function(semantic: &SemanticModel) -> bool {
semantic
.current_statements()
.find_map(|stmt| stmt.as_function_def_stmt())
.is_some_and(|function_def| is_airflow_task(function_def, semantic))
}
Copy link
Member

Choose a reason for hiding this comment

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

Prefer to have this above is_airflow_task since it depends on it.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants