Skip to content

Commit 7e08683

Browse files
committed
refactor: use explicit path
1 parent 405cfdd commit 7e08683

File tree

5 files changed

+50
-10
lines changed

5 files changed

+50
-10
lines changed

crates/ruff_linter/resources/test/fixtures/airflow/AIR301_class_attribute.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
lfb = LocalFilesystemBackend()
104104
lfb.get_connections()
105105

106+
from airflow.models import DAG
107+
108+
# airflow.DAG
109+
test_dag = DAG(dag_id="test_dag")
110+
test_dag.create_dagrun()
111+
106112
from airflow import DAG
107113

108114
# airflow.DAG

crates/ruff_linter/src/rules/airflow/rules/removal_in_3.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,12 @@ fn check_method(checker: &Checker, call_expr: &ExprCall) {
492492
"collected_datasets" => Replacement::AttrName("collected_assets"),
493493
_ => return,
494494
},
495-
["airflow", .., "DAG"] => match attr.as_str() {
496-
"create_dagrun" => Replacement::None,
497-
_ => return,
498-
},
495+
["airflow", "models", "dag", "DAG"] | ["airflow", "models", "DAG"] | ["airflow", "DAG"] => {
496+
match attr.as_str() {
497+
"create_dagrun" => Replacement::None,
498+
_ => return,
499+
}
500+
}
499501
["airflow", "providers_manager", "ProvidersManager"] => match attr.as_str() {
500502
"initialize_providers_dataset_uri_resources" => {
501503
Replacement::AttrName("initialize_providers_asset_uri_resources")

crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,12 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
288288
},
289289

290290
// airflow.model..DAG
291-
["airflow", "models", .., "DAG"] => Replacement::SourceModuleMoved {
292-
module: "airflow.sdk",
293-
name: "DAG".to_string(),
294-
},
291+
["airflow", "models", "dag", "DAG"] | ["airflow", "models", "DAG"] | ["airflow", "DAG"] => {
292+
Replacement::SourceModuleMoved {
293+
module: "airflow.sdk",
294+
name: "DAG".to_string(),
295+
}
296+
}
295297

296298
// airflow.sensors.base
297299
[

crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR301_AIR301_class_attribute.py.snap

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ AIR301 [*] `get_connections` is removed in Airflow 3.0
641641
104 | lfb.get_connections()
642642
| ^^^^^^^^^^^^^^^
643643
105 |
644-
106 | from airflow import DAG
644+
106 | from airflow.models import DAG
645645
|
646646
help: Use `get_connection` instead
647647
101 |
@@ -650,7 +650,7 @@ help: Use `get_connection` instead
650650
- lfb.get_connections()
651651
104 + lfb.get_connection()
652652
105 |
653-
106 | from airflow import DAG
653+
106 | from airflow.models import DAG
654654
107 |
655655

656656
AIR301 `create_dagrun` is removed in Airflow 3.0
@@ -660,4 +660,15 @@ AIR301 `create_dagrun` is removed in Airflow 3.0
660660
109 | test_dag = DAG(dag_id="test_dag")
661661
110 | test_dag.create_dagrun()
662662
| ^^^^^^^^^^^^^
663+
111 |
664+
112 | from airflow import DAG
665+
|
666+
667+
AIR301 `create_dagrun` is removed in Airflow 3.0
668+
--> AIR301_class_attribute.py:116:10
669+
|
670+
114 | # airflow.DAG
671+
115 | test_dag = DAG(dag_id="test_dag")
672+
116 | test_dag.create_dagrun()
673+
| ^^^^^^^^^^^^^
663674
|

crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_args.py.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
---
22
source: crates/ruff_linter/src/rules/airflow/mod.rs
33
---
4+
AIR311 [*] `airflow.DAG` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
5+
--> AIR311_args.py:13:1
6+
|
7+
13 | DAG(dag_id="class_sla_callback", sla_miss_callback=sla_callback)
8+
| ^^^
9+
|
10+
help: Use `DAG` from `airflow.sdk` instead.
11+
2 |
12+
3 | from datetime import timedelta
13+
4 |
14+
- from airflow import DAG, dag
15+
5 + from airflow import dag
16+
6 | from airflow.operators.datetime import BranchDateTimeOperator
17+
7 + from airflow.sdk import DAG
18+
8 |
19+
9 |
20+
10 | def sla_callback(*arg, **kwargs):
21+
note: This is an unsafe fix and may change runtime behavior
22+
423
AIR311 `sla_miss_callback` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
524
--> AIR311_args.py:13:34
625
|

0 commit comments

Comments
 (0)