@@ -48,6 +48,7 @@ use crate::importer::ImportRequest;
48
48
pub struct Numpy2Deprecation {
49
49
existing : String ,
50
50
migration_guide : Option < String > ,
51
+ code_action : Option < String > ,
51
52
}
52
53
53
54
impl Violation for Numpy2Deprecation {
@@ -58,21 +59,23 @@ impl Violation for Numpy2Deprecation {
58
59
let Numpy2Deprecation {
59
60
existing,
60
61
migration_guide,
62
+ code_action : _,
61
63
} = self ;
62
64
match migration_guide {
63
65
Some ( migration_guide) => {
64
66
format ! ( "`np.{existing}` will be removed in NumPy 2.0. {migration_guide}" , )
65
67
}
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" ) ,
67
69
}
68
70
}
69
71
70
72
fn fix_title ( & self ) -> Option < String > {
71
73
let Numpy2Deprecation {
72
74
existing : _,
73
- migration_guide,
75
+ migration_guide : _,
76
+ code_action,
74
77
} = self ;
75
- migration_guide . clone ( )
78
+ code_action . clone ( )
76
79
}
77
80
}
78
81
@@ -117,6 +120,27 @@ impl Details<'_> {
117
120
Details :: Manual { guideline } => guideline. map ( ToString :: to_string) ,
118
121
}
119
122
}
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
+ }
120
144
}
121
145
122
146
#[ derive( Debug ) ]
@@ -501,6 +525,7 @@ pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) {
501
525
Numpy2Deprecation {
502
526
existing : replacement. existing . to_string ( ) ,
503
527
migration_guide : replacement. details . guideline ( ) ,
528
+ code_action : replacement. details . code_action ( ) ,
504
529
} ,
505
530
expr. range ( ) ,
506
531
) ;
0 commit comments