Skip to content

Commit 536ac55

Browse files
Remove trailing periods from NumPy 2.0 code actions (#8475)
Very minor consistency thing with other rules. For code actions, we tend to say `Replace with {X}` rathern than `Use {X} instead.`
1 parent f2335fe commit 536ac55

File tree

2 files changed

+62
-54
lines changed

2 files changed

+62
-54
lines changed

crates/ruff_linter/src/rules/numpy/rules/numpy_2_0_deprecation.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use crate::importer::ImportRequest;
4848
pub struct Numpy2Deprecation {
4949
existing: String,
5050
migration_guide: Option<String>,
51+
code_action: Option<String>,
5152
}
5253

5354
impl Violation for Numpy2Deprecation {
@@ -58,21 +59,23 @@ impl Violation for Numpy2Deprecation {
5859
let Numpy2Deprecation {
5960
existing,
6061
migration_guide,
62+
code_action: _,
6163
} = self;
6264
match migration_guide {
6365
Some(migration_guide) => {
6466
format!("`np.{existing}` will be removed in NumPy 2.0. {migration_guide}",)
6567
}
66-
None => format!("`np.{existing}` will be removed without replacement in NumPy 2.0."),
68+
None => format!("`np.{existing}` will be removed without replacement in NumPy 2.0"),
6769
}
6870
}
6971

7072
fn fix_title(&self) -> Option<String> {
7173
let Numpy2Deprecation {
7274
existing: _,
73-
migration_guide,
75+
migration_guide: _,
76+
code_action,
7477
} = self;
75-
migration_guide.clone()
78+
code_action.clone()
7679
}
7780
}
7881

@@ -117,6 +120,27 @@ impl Details<'_> {
117120
Details::Manual { guideline } => guideline.map(ToString::to_string),
118121
}
119122
}
123+
124+
fn code_action(&self) -> Option<String> {
125+
match self {
126+
Details::AutoImport {
127+
path,
128+
name,
129+
compatibility: Compatibility::BackwardsCompatible,
130+
} => Some(format!("Replace with `{path}.{name}`")),
131+
Details::AutoImport {
132+
path,
133+
name,
134+
compatibility: Compatibility::Breaking,
135+
} => Some(format!(
136+
"Replace with `{path}.{name}` (requires NumPy 2.0 or greater)"
137+
)),
138+
Details::AutoPurePython { python_expr } => {
139+
Some(format!("Replace with `{python_expr}`"))
140+
}
141+
Details::Manual { guideline: _ } => None,
142+
}
143+
}
120144
}
121145

122146
#[derive(Debug)]
@@ -501,6 +525,7 @@ pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) {
501525
Numpy2Deprecation {
502526
existing: replacement.existing.to_string(),
503527
migration_guide: replacement.details.guideline(),
528+
code_action: replacement.details.code_action(),
504529
},
505530
expr.range(),
506531
);

0 commit comments

Comments
 (0)