Skip to content

Commit 6ef68e7

Browse files
committed
add a new item in enum for raising internal module warning message
1 parent bdb3609 commit 6ef68e7

5 files changed

Lines changed: 50 additions & 54 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ pub(crate) enum Replacement {
3333
module: &'static str,
3434
name: String,
3535
},
36-
// Symbols moved to Task SDK in Airflow 3 with only module changed. Used when we want to match multiple names.
36+
// Symbols moved to Task SDK in Airflow 3. Used when we want to match multiple names.
3737
// e.g., `airflow.io.get_fs | has_fs | Properties` to `airflow.sdk.io.get_fs | has_fs | Properties`
3838
SourceModuleMovedToSDK {
3939
module: &'static str,
4040
name: String,
4141
version: &'static str,
4242
},
43+
// Symbols moved to internal module in Airflow 3. Used when we want to raise a warning.
44+
// e.g., `airflow.utils.setup_teardown.BaseSetupTeardownContext` to `airflow.sdk.definitions._internal.setup_teardown.BaseSetupTeardownContext`
45+
InternalModule {
46+
module: &'static str,
47+
name: String,
48+
},
4349
}
4450

4551
#[derive(Clone, Debug, Eq, PartialEq)]

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ impl Violation for Airflow3Removal {
6464
| Replacement::SourceModuleMoved { module: _, name: _ }
6565
| Replacement::SourceModuleMovedToSDK {
6666
module: _, name: _, ..
67-
} => {
67+
}
68+
| Replacement::InternalModule { module: _, name: _ } => {
6869
format!("`{deprecated}` is removed in Airflow 3.0")
6970
}
7071
}
@@ -89,6 +90,10 @@ impl Violation for Airflow3Removal {
8990
} => Some(format!(
9091
"`{name}` has been moved to `{module}` since Airflow 3.0 (with apache-airflow-task-sdk>={version})."
9192
)),
93+
Replacement::InternalModule { module, name } => Some(format!(
94+
"`{name}` has been moved to `{module}` since Airflow 3.0. \
95+
This is an internal module which is not supposed to be used and is subject to change without notice."
96+
)),
9297
}
9398
}
9499
}

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

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ impl Violation for Airflow31Removal {
5656
| Replacement::SourceModuleMoved { module: _, name: _ }
5757
| Replacement::SourceModuleMovedToSDK {
5858
module: _, name: _, ..
59-
} => {
59+
}
60+
| Replacement::InternalModule { module: _, name: _ } => {
6061
format!("`{deprecated}` is removed in Airflow 3.1")
6162
}
6263
}
@@ -81,6 +82,10 @@ impl Violation for Airflow31Removal {
8182
} => Some(format!(
8283
"`{name}` has been moved to `{module}` since Airflow 3.1 (with apache-airflow-task-sdk>={version})."
8384
)),
85+
Replacement::InternalModule { module, name } => Some(format!(
86+
"`{name}` has been moved to `{module}` since Airflow 3.1. \
87+
This is an internal module which is not supposed to be used and is subject to change without notice."
88+
)),
8489
}
8590
}
8691
}
@@ -130,23 +135,19 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
130135
"airflow",
131136
"utils",
132137
"setup_teardown",
133-
"BaseSetupTeardownContext",
134-
] => Replacement::Message(
135-
"`BaseSetupTeardownContext` has been moved to `airflow.sdk.definitions._internal.setup_teardown` \
136-
since Airflow 3.1. This is an internal module and is subject to change without notice.",
137-
),
138-
["airflow", "utils", "setup_teardown", "SetupTeardownContext"] => Replacement::Message(
139-
"`SetupTeardownContext` has been moved to `airflow.sdk.definitions._internal.setup_teardown` \
140-
since Airflow 3.1. This is an internal module and is subject to change without notice.",
141-
),
138+
rest @ ("BaseSetupTeardownContext" | "SetupTeardownContext"),
139+
] => Replacement::InternalModule {
140+
module: "airflow.sdk.definitions._internal.setup_teardown",
141+
name: rest.to_string(),
142+
},
142143
// airflow.secrets
143144
["airflow", "secrets", "cache", "SecretCache"] => Replacement::SourceModuleMovedToSDK {
144145
module: "airflow.sdk",
145146
name: "SecretCache".to_string(),
146147
version: "1.1.6",
147148
},
148149
// airflow.utils.xcom
149-
["airflow", "utils", "xcom", "XCOM_RETURN_KEY"] => Replacement::SourceModuleMoved {
150+
["airflow", "utils", "xcom", "XCOM_RETURN_KEY"] => Replacement::InternalModule {
150151
module: "airflow.models.xcom",
151152
name: "XCOM_RETURN_KEY".to_string(),
152153
},
@@ -169,37 +170,25 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) {
169170
version: "1.1.6",
170171
},
171172
// airflow.utils.decorators
172-
["airflow", "utils", "decorators", "remove_task_decorator"] => Replacement::Message(
173-
"`remove_task_decorator` has been moved to `airflow.sdk.definitions._internal.decorators` \
174-
since Airflow 3.1. This is an internal module and is subject to change without notice.",
175-
),
176173
[
177174
"airflow",
178175
"utils",
179176
"decorators",
180-
"fixup_decorator_warning_stack",
181-
] => Replacement::Message(
182-
"`fixup_decorator_warning_stack` has been moved to `airflow.sdk.definitions._internal.decorators` \
183-
since Airflow 3.1. This is an internal module and is subject to change without notice.",
184-
),
177+
rest @ ("remove_task_decorator" | "fixup_decorator_warning_stack"),
178+
] => Replacement::InternalModule {
179+
module: "airflow.sdk.definitions._internal.decorators",
180+
name: rest.to_string(),
181+
},
185182
// airflow.models.abstractoperator
186-
["airflow", "models", "abstractoperator", "AbstractOperator"] => Replacement::Message(
187-
"`AbstractOperator` has been moved to `airflow.sdk.definitions._internal.abstractoperator` \
188-
since Airflow 3.1. This is an internal module and is subject to change without notice.",
189-
),
190-
["airflow", "models", "abstractoperator", "NotMapped"] => Replacement::Message(
191-
"`NotMapped` has been moved to `airflow.sdk.definitions._internal.abstractoperator` \
192-
since Airflow 3.1. This is an internal module and is subject to change without notice.",
193-
),
194183
[
195184
"airflow",
196185
"models",
197186
"abstractoperator",
198-
"TaskStateChangeCallback",
199-
] => Replacement::Message(
200-
"`TaskStateChangeCallback` has been moved to `airflow.sdk.definitions._internal.abstractoperator` \
201-
since Airflow 3.1. This is an internal module and is subject to change without notice.",
202-
),
187+
rest @ ("AbstractOperator" | "NotMapped" | "TaskStateChangeCallback"),
188+
] => Replacement::InternalModule {
189+
module: "airflow.sdk.definitions._internal.abstractoperator",
190+
name: rest.to_string(),
191+
},
203192
// airflow.models.baseoperator
204193
["airflow", "models", "baseoperator", "BaseOperator"] => {
205194
Replacement::SourceModuleMovedToSDK {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ impl Violation for Airflow3SuggestedUpdate {
6060
| Replacement::SourceModuleMoved { module: _, name: _ }
6161
| Replacement::SourceModuleMovedToSDK {
6262
module: _, name: _, ..
63-
} => {
63+
}
64+
| Replacement::InternalModule { module: _, name: _ } => {
6465
format!(
6566
"`{deprecated}` is removed in Airflow 3.0; \
6667
It still works in Airflow 3.0 but is expected to be removed in a future version."
@@ -88,6 +89,10 @@ impl Violation for Airflow3SuggestedUpdate {
8889
} => Some(format!(
8990
"`{name}` has been moved to `{module}` since Airflow 3.0 (with apache-airflow-task-sdk>={version})."
9091
)),
92+
Replacement::InternalModule { module, name } => Some(format!(
93+
"`{name}` has been moved to `{module}` since Airflow 3.0. \
94+
This is an internal module which is not supposed to be used and is subject to change without notice."
95+
)),
9196
}
9297
}
9398
}

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ AIR321 `airflow.utils.setup_teardown.BaseSetupTeardownContext` is removed in Air
1010
| ^^^^^^^^^^^^^^^^^^^^^^^^
1111
10 | SetupTeardownContext()
1212
|
13-
help: `BaseSetupTeardownContext` has been moved to `airflow.sdk.definitions._internal.setup_teardown` since Airflow 3.1. This is an internal module and is subject to change without notice.
13+
help: `BaseSetupTeardownContext` has been moved to `airflow.sdk.definitions._internal.setup_teardown` since Airflow 3.1. This is an internal module which is not supposed to be used and is subject to change without notice.
1414

1515
AIR321 `airflow.utils.setup_teardown.SetupTeardownContext` is removed in Airflow 3.1
1616
--> AIR321_names.py:10:1
@@ -21,9 +21,9 @@ AIR321 `airflow.utils.setup_teardown.SetupTeardownContext` is removed in Airflow
2121
11 |
2222
12 | # airflow.utils.xcom
2323
|
24-
help: `SetupTeardownContext` has been moved to `airflow.sdk.definitions._internal.setup_teardown` since Airflow 3.1. This is an internal module and is subject to change without notice.
24+
help: `SetupTeardownContext` has been moved to `airflow.sdk.definitions._internal.setup_teardown` since Airflow 3.1. This is an internal module which is not supposed to be used and is subject to change without notice.
2525

26-
AIR321 [*] `airflow.utils.xcom.XCOM_RETURN_KEY` is removed in Airflow 3.1
26+
AIR321 `airflow.utils.xcom.XCOM_RETURN_KEY` is removed in Airflow 3.1
2727
--> AIR321_names.py:15:1
2828
|
2929
13 | from airflow.utils.xcom import XCOM_RETURN_KEY
@@ -33,16 +33,7 @@ AIR321 [*] `airflow.utils.xcom.XCOM_RETURN_KEY` is removed in Airflow 3.1
3333
16 |
3434
17 | # airflow.utils.task_group
3535
|
36-
help: Use `XCOM_RETURN_KEY` from `airflow.models.xcom` instead.
37-
10 | SetupTeardownContext()
38-
11 |
39-
12 | # airflow.utils.xcom
40-
- from airflow.utils.xcom import XCOM_RETURN_KEY
41-
13 + from airflow.models.xcom import XCOM_RETURN_KEY
42-
14 |
43-
15 | XCOM_RETURN_KEY
44-
16 |
45-
note: This is an unsafe fix and may change runtime behavior
36+
help: `XCOM_RETURN_KEY` has been moved to `airflow.models.xcom` since Airflow 3.1. This is an internal module which is not supposed to be used and is subject to change without notice.
4637

4738
AIR321 [*] `airflow.utils.task_group.TaskGroup` is removed in Airflow 3.1
4839
--> AIR321_names.py:20:1
@@ -247,7 +238,7 @@ AIR321 `airflow.utils.decorators.remove_task_decorator` is removed in Airflow 3.
247238
| ^^^^^^^^^^^^^^^^^^^^^
248239
51 | fixup_decorator_warning_stack()
249240
|
250-
help: `remove_task_decorator` has been moved to `airflow.sdk.definitions._internal.decorators` since Airflow 3.1. This is an internal module and is subject to change without notice.
241+
help: `remove_task_decorator` has been moved to `airflow.sdk.definitions._internal.decorators` since Airflow 3.1. This is an internal module which is not supposed to be used and is subject to change without notice.
251242

252243
AIR321 `airflow.utils.decorators.fixup_decorator_warning_stack` is removed in Airflow 3.1
253244
--> AIR321_names.py:51:1
@@ -258,7 +249,7 @@ AIR321 `airflow.utils.decorators.fixup_decorator_warning_stack` is removed in Ai
258249
52 |
259250
53 | # airflow.models.abstractoperator
260251
|
261-
help: `fixup_decorator_warning_stack` has been moved to `airflow.sdk.definitions._internal.decorators` since Airflow 3.1. This is an internal module and is subject to change without notice.
252+
help: `fixup_decorator_warning_stack` has been moved to `airflow.sdk.definitions._internal.decorators` since Airflow 3.1. This is an internal module which is not supposed to be used and is subject to change without notice.
262253

263254
AIR321 `airflow.models.abstractoperator.AbstractOperator` is removed in Airflow 3.1
264255
--> AIR321_names.py:60:1
@@ -270,7 +261,7 @@ AIR321 `airflow.models.abstractoperator.AbstractOperator` is removed in Airflow
270261
61 | NotMapped()
271262
62 | TaskStateChangeCallback()
272263
|
273-
help: `AbstractOperator` has been moved to `airflow.sdk.definitions._internal.abstractoperator` since Airflow 3.1. This is an internal module and is subject to change without notice.
264+
help: `AbstractOperator` has been moved to `airflow.sdk.definitions._internal.abstractoperator` since Airflow 3.1. This is an internal module which is not supposed to be used and is subject to change without notice.
274265

275266
AIR321 `airflow.models.abstractoperator.NotMapped` is removed in Airflow 3.1
276267
--> AIR321_names.py:61:1
@@ -280,7 +271,7 @@ AIR321 `airflow.models.abstractoperator.NotMapped` is removed in Airflow 3.1
280271
| ^^^^^^^^^
281272
62 | TaskStateChangeCallback()
282273
|
283-
help: `NotMapped` has been moved to `airflow.sdk.definitions._internal.abstractoperator` since Airflow 3.1. This is an internal module and is subject to change without notice.
274+
help: `NotMapped` has been moved to `airflow.sdk.definitions._internal.abstractoperator` since Airflow 3.1. This is an internal module which is not supposed to be used and is subject to change without notice.
284275

285276
AIR321 `airflow.models.abstractoperator.TaskStateChangeCallback` is removed in Airflow 3.1
286277
--> AIR321_names.py:62:1
@@ -292,7 +283,7 @@ AIR321 `airflow.models.abstractoperator.TaskStateChangeCallback` is removed in A
292283
63 |
293284
64 | # airflow.models.baseoperator
294285
|
295-
help: `TaskStateChangeCallback` has been moved to `airflow.sdk.definitions._internal.abstractoperator` since Airflow 3.1. This is an internal module and is subject to change without notice.
286+
help: `TaskStateChangeCallback` has been moved to `airflow.sdk.definitions._internal.abstractoperator` since Airflow 3.1. This is an internal module which is not supposed to be used and is subject to change without notice.
296287

297288
AIR321 [*] `airflow.models.baseoperator.BaseOperator` is removed in Airflow 3.1
298289
--> AIR321_names.py:67:1

0 commit comments

Comments
 (0)