Skip to content

Commit f126f58

Browse files
committed
feat(AIR311): apply Replacement::AutoImport
1 parent 1796ca9 commit f126f58

File tree

2 files changed

+126
-19
lines changed

2 files changed

+126
-19
lines changed

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

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,33 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
194194

195195
let replacement = match qualified_name.segments() {
196196
// airflow.datasets.metadata
197-
["airflow", "datasets", "metadata", "Metadata"] => {
198-
Replacement::Name("airflow.sdk.Metadata")
199-
}
197+
["airflow", "datasets", "metadata", "Metadata"] => Replacement::AutoImport {
198+
module: "airflow.sdk",
199+
name: "Metadata",
200+
},
200201
// airflow.datasets
201202
["airflow", "Dataset"] | ["airflow", "datasets", "Dataset"] => Replacement::AutoImport {
202203
module: "airflow.sdk",
203204
name: "Asset",
204205
},
205206
["airflow", "datasets", rest] => match *rest {
206207
"DatasetAliasEvent" => Replacement::None,
207-
"DatasetAlias" => Replacement::Name("airflow.sdk.AssetAlias"),
208-
"DatasetAll" => Replacement::Name("airflow.sdk.AssetAll"),
209-
"DatasetAny" => Replacement::Name("airflow.sdk.AssetAny"),
210-
"expand_alias_to_datasets" => Replacement::Name("airflow.sdk.expand_alias_to_assets"),
208+
"DatasetAlias" => Replacement::AutoImport {
209+
module: "airflow.sdk",
210+
name: "AssetAlias",
211+
},
212+
"DatasetAll" => Replacement::AutoImport {
213+
module: "airflow.sdk",
214+
name: "AssetAll",
215+
},
216+
"DatasetAny" => Replacement::AutoImport {
217+
module: "airflow.sdk",
218+
name: "AssetAny",
219+
},
220+
"expand_alias_to_datasets" => Replacement::AutoImport {
221+
module: "airflow.sdk",
222+
name: "expand_alias_to_assets",
223+
},
211224
_ => return,
212225
},
213226

@@ -235,9 +248,10 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
235248
module: "airflow.sdk",
236249
name: (*rest).to_string(),
237250
},
238-
"BaseOperatorLink" => {
239-
Replacement::Name("airflow.sdk.definitions.baseoperatorlink.BaseOperatorLink")
240-
}
251+
"BaseOperatorLink" => Replacement::AutoImport {
252+
module: "airflow.sdk.definitions.baseoperatorlink",
253+
name: "BaseOperatorLink",
254+
},
241255
_ => return,
242256
},
243257
// airflow.model..DAG
@@ -246,12 +260,16 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
246260
name: "DAG".to_string(),
247261
},
248262
// airflow.timetables
249-
["airflow", "timetables", "datasets", "DatasetOrTimeSchedule"] => {
250-
Replacement::Name("airflow.timetables.assets.AssetOrTimeSchedule")
251-
}
263+
["airflow", "timetables", "datasets", "DatasetOrTimeSchedule"] => Replacement::AutoImport {
264+
module: "airflow.timetables.assets",
265+
name: "AssetOrTimeSchedule",
266+
},
252267
// airflow.utils
253268
["airflow", "utils", "dag_parsing_context", "get_parsing_context"] => {
254-
Replacement::Name("airflow.sdk.get_parsing_context")
269+
Replacement::AutoImport {
270+
module: "airflow.sdk",
271+
name: "get_parsing_context",
272+
}
255273
}
256274

257275
_ => return,

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

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ AIR311_names.py:26:1: AIR311 [*] `airflow.datasets.Dataset` is removed in Airflo
5050
28 29 | DatasetAll()
5151
29 30 | DatasetAny()
5252

53-
AIR311_names.py:27:1: AIR311 `airflow.datasets.DatasetAlias` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
53+
AIR311_names.py:27:1: AIR311 [*] `airflow.datasets.DatasetAlias` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
5454
|
5555
25 | # airflow.datasets
5656
26 | Dataset()
@@ -61,7 +61,24 @@ AIR311_names.py:27:1: AIR311 `airflow.datasets.DatasetAlias` is removed in Airfl
6161
|
6262
= help: Use `airflow.sdk.AssetAlias` instead
6363

64-
AIR311_names.py:28:1: AIR311 `airflow.datasets.DatasetAll` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
64+
Safe fix
65+
18 18 | from airflow.models.dag import DAG as DAGFromDag
66+
19 19 | from airflow.timetables.datasets import DatasetOrTimeSchedule
67+
20 20 | from airflow.utils.dag_parsing_context import get_parsing_context
68+
21 |+from airflow.sdk import AssetAlias
69+
21 22 |
70+
22 23 | # airflow
71+
23 24 | DatasetFromRoot()
72+
24 25 |
73+
25 26 | # airflow.datasets
74+
26 27 | Dataset()
75+
27 |-DatasetAlias()
76+
28 |+AssetAlias()
77+
28 29 | DatasetAll()
78+
29 30 | DatasetAny()
79+
30 31 | Metadata()
80+
81+
AIR311_names.py:28:1: AIR311 [*] `airflow.datasets.DatasetAll` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
6582
|
6683
26 | Dataset()
6784
27 | DatasetAlias()
@@ -72,7 +89,25 @@ AIR311_names.py:28:1: AIR311 `airflow.datasets.DatasetAll` is removed in Airflow
7289
|
7390
= help: Use `airflow.sdk.AssetAll` instead
7491

75-
AIR311_names.py:29:1: AIR311 `airflow.datasets.DatasetAny` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
92+
Safe fix
93+
18 18 | from airflow.models.dag import DAG as DAGFromDag
94+
19 19 | from airflow.timetables.datasets import DatasetOrTimeSchedule
95+
20 20 | from airflow.utils.dag_parsing_context import get_parsing_context
96+
21 |+from airflow.sdk import AssetAll
97+
21 22 |
98+
22 23 | # airflow
99+
23 24 | DatasetFromRoot()
100+
--------------------------------------------------------------------------------
101+
25 26 | # airflow.datasets
102+
26 27 | Dataset()
103+
27 28 | DatasetAlias()
104+
28 |-DatasetAll()
105+
29 |+AssetAll()
106+
29 30 | DatasetAny()
107+
30 31 | Metadata()
108+
31 32 | expand_alias_to_datasets()
109+
110+
AIR311_names.py:29:1: AIR311 [*] `airflow.datasets.DatasetAny` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
76111
|
77112
27 | DatasetAlias()
78113
28 | DatasetAll()
@@ -83,6 +118,24 @@ AIR311_names.py:29:1: AIR311 `airflow.datasets.DatasetAny` is removed in Airflow
83118
|
84119
= help: Use `airflow.sdk.AssetAny` instead
85120

121+
Safe fix
122+
18 18 | from airflow.models.dag import DAG as DAGFromDag
123+
19 19 | from airflow.timetables.datasets import DatasetOrTimeSchedule
124+
20 20 | from airflow.utils.dag_parsing_context import get_parsing_context
125+
21 |+from airflow.sdk import AssetAny
126+
21 22 |
127+
22 23 | # airflow
128+
23 24 | DatasetFromRoot()
129+
--------------------------------------------------------------------------------
130+
26 27 | Dataset()
131+
27 28 | DatasetAlias()
132+
28 29 | DatasetAll()
133+
29 |-DatasetAny()
134+
30 |+AssetAny()
135+
30 31 | Metadata()
136+
31 32 | expand_alias_to_datasets()
137+
32 33 |
138+
86139
AIR311_names.py:30:1: AIR311 `airflow.datasets.metadata.Metadata` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
87140
|
88141
28 | DatasetAll()
@@ -93,7 +146,7 @@ AIR311_names.py:30:1: AIR311 `airflow.datasets.metadata.Metadata` is removed in
93146
|
94147
= help: Use `airflow.sdk.Metadata` instead
95148

96-
AIR311_names.py:31:1: AIR311 `airflow.datasets.expand_alias_to_datasets` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
149+
AIR311_names.py:31:1: AIR311 [*] `airflow.datasets.expand_alias_to_datasets` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
97150
|
98151
29 | DatasetAny()
99152
30 | Metadata()
@@ -104,6 +157,24 @@ AIR311_names.py:31:1: AIR311 `airflow.datasets.expand_alias_to_datasets` is remo
104157
|
105158
= help: Use `airflow.sdk.expand_alias_to_assets` instead
106159

160+
Safe fix
161+
18 18 | from airflow.models.dag import DAG as DAGFromDag
162+
19 19 | from airflow.timetables.datasets import DatasetOrTimeSchedule
163+
20 20 | from airflow.utils.dag_parsing_context import get_parsing_context
164+
21 |+from airflow.sdk import expand_alias_to_assets
165+
21 22 |
166+
22 23 | # airflow
167+
23 24 | DatasetFromRoot()
168+
--------------------------------------------------------------------------------
169+
28 29 | DatasetAll()
170+
29 30 | DatasetAny()
171+
30 31 | Metadata()
172+
31 |-expand_alias_to_datasets()
173+
32 |+expand_alias_to_assets()
174+
32 33 |
175+
33 34 | # airflow.decorators
176+
34 35 | dag()
177+
107178
AIR311_names.py:34:1: AIR311 `airflow.decorators.dag` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
108179
|
109180
33 | # airflow.decorators
@@ -228,7 +299,7 @@ AIR311_names.py:56:1: AIR311 `airflow.models.dag.DAG` is removed in Airflow 3.0;
228299
|
229300
= help: Use `airflow.sdk.DAG` instead
230301

231-
AIR311_names.py:58:1: AIR311 `airflow.timetables.datasets.DatasetOrTimeSchedule` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
302+
AIR311_names.py:58:1: AIR311 [*] `airflow.timetables.datasets.DatasetOrTimeSchedule` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
232303
|
233304
56 | DAGFromDag()
234305
57 | # airflow.timetables.datasets
@@ -239,6 +310,24 @@ AIR311_names.py:58:1: AIR311 `airflow.timetables.datasets.DatasetOrTimeSchedule`
239310
|
240311
= help: Use `airflow.timetables.assets.AssetOrTimeSchedule` instead
241312

313+
Safe fix
314+
18 18 | from airflow.models.dag import DAG as DAGFromDag
315+
19 19 | from airflow.timetables.datasets import DatasetOrTimeSchedule
316+
20 20 | from airflow.utils.dag_parsing_context import get_parsing_context
317+
21 |+from airflow.timetables.assets import AssetOrTimeSchedule
318+
21 22 |
319+
22 23 | # airflow
320+
23 24 | DatasetFromRoot()
321+
--------------------------------------------------------------------------------
322+
55 56 | # airflow.models.dag
323+
56 57 | DAGFromDag()
324+
57 58 | # airflow.timetables.datasets
325+
58 |-DatasetOrTimeSchedule()
326+
59 |+AssetOrTimeSchedule()
327+
59 60 |
328+
60 61 | # airflow.utils.dag_parsing_context
329+
61 62 | get_parsing_context()
330+
242331
AIR311_names.py:61:1: AIR311 `airflow.utils.dag_parsing_context.get_parsing_context` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version.
243332
|
244333
60 | # airflow.utils.dag_parsing_context

0 commit comments

Comments
 (0)