mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:41:23 +00:00
Refactor NPY201 (#12479)
This commit is contained in:
parent
3af6ccb720
commit
c1b292a0dc
1 changed files with 542 additions and 542 deletions
|
@ -151,517 +151,520 @@ enum Compatibility {
|
||||||
/// The change is breaking in NumPy 2.0.
|
/// The change is breaking in NumPy 2.0.
|
||||||
Breaking,
|
Breaking,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// NPY201
|
/// NPY201
|
||||||
pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) {
|
pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) {
|
||||||
if !checker.semantic().seen_module(Modules::NUMPY) {
|
let semantic = checker.semantic();
|
||||||
|
|
||||||
|
if !semantic.seen_module(Modules::NUMPY) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let maybe_replacement = checker
|
let Some(qualified_name) = semantic.resolve_qualified_name(expr) else {
|
||||||
.semantic()
|
return;
|
||||||
.resolve_qualified_name(expr)
|
};
|
||||||
.and_then(|qualified_name| match qualified_name.segments() {
|
|
||||||
|
let replacement = match qualified_name.segments() {
|
||||||
// NumPy's main namespace np.* members removed in 2.0
|
// NumPy's main namespace np.* members removed in 2.0
|
||||||
["numpy", "add_docstring"] => Some(Replacement {
|
["numpy", "add_docstring"] => Replacement {
|
||||||
existing: "add_docstring",
|
existing: "add_docstring",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.lib",
|
path: "numpy.lib",
|
||||||
name: "add_docstring",
|
name: "add_docstring",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "add_newdoc"] => Some(Replacement {
|
["numpy", "add_newdoc"] => Replacement {
|
||||||
existing: "add_newdoc",
|
existing: "add_newdoc",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.lib",
|
path: "numpy.lib",
|
||||||
name: "add_newdoc",
|
name: "add_newdoc",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "add_newdoc_ufunc"] => Some(Replacement {
|
["numpy", "add_newdoc_ufunc"] => Replacement {
|
||||||
existing: "add_newdoc_ufunc",
|
existing: "add_newdoc_ufunc",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("`add_newdoc_ufunc` is an internal function."),
|
guideline: Some("`add_newdoc_ufunc` is an internal function."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "alltrue"] => Some(Replacement {
|
["numpy", "alltrue"] => Replacement {
|
||||||
existing: "alltrue",
|
existing: "alltrue",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "all",
|
name: "all",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "asfarray"] => Some(Replacement {
|
["numpy", "asfarray"] => Replacement {
|
||||||
existing: "asfarray",
|
existing: "asfarray",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use `np.asarray` with a `float` dtype instead."),
|
guideline: Some("Use `np.asarray` with a `float` dtype instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "byte_bounds"] => Some(Replacement {
|
["numpy", "byte_bounds"] => Replacement {
|
||||||
existing: "byte_bounds",
|
existing: "byte_bounds",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.lib.array_utils",
|
path: "numpy.lib.array_utils",
|
||||||
name: "byte_bounds",
|
name: "byte_bounds",
|
||||||
compatibility: Compatibility::Breaking,
|
compatibility: Compatibility::Breaking,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "cast"] => Some(Replacement {
|
["numpy", "cast"] => Replacement {
|
||||||
existing: "cast",
|
existing: "cast",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use `np.asarray(arr, dtype=dtype)` instead."),
|
guideline: Some("Use `np.asarray(arr, dtype=dtype)` instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "cfloat"] => Some(Replacement {
|
["numpy", "cfloat"] => Replacement {
|
||||||
existing: "cfloat",
|
existing: "cfloat",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "complex128",
|
name: "complex128",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "clongfloat"] => Some(Replacement {
|
["numpy", "clongfloat"] => Replacement {
|
||||||
existing: "clongfloat",
|
existing: "clongfloat",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "clongdouble",
|
name: "clongdouble",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "compat"] => Some(Replacement {
|
["numpy", "compat"] => Replacement {
|
||||||
existing: "compat",
|
existing: "compat",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Python 2 is no longer supported."),
|
guideline: Some("Python 2 is no longer supported."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "complex_"] => Some(Replacement {
|
["numpy", "complex_"] => Replacement {
|
||||||
existing: "complex_",
|
existing: "complex_",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "complex128",
|
name: "complex128",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "cumproduct"] => Some(Replacement {
|
["numpy", "cumproduct"] => Replacement {
|
||||||
existing: "cumproduct",
|
existing: "cumproduct",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "cumprod",
|
name: "cumprod",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "DataSource"] => Some(Replacement {
|
["numpy", "DataSource"] => Replacement {
|
||||||
existing: "DataSource",
|
existing: "DataSource",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.lib.npyio",
|
path: "numpy.lib.npyio",
|
||||||
name: "DataSource",
|
name: "DataSource",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "deprecate"] => Some(Replacement {
|
["numpy", "deprecate"] => Replacement {
|
||||||
existing: "deprecate",
|
existing: "deprecate",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Emit `DeprecationWarning` with `warnings.warn` directly, or use `typing.deprecated`."),
|
guideline: Some("Emit `DeprecationWarning` with `warnings.warn` directly, or use `typing.deprecated`."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "deprecate_with_doc"] => Some(Replacement {
|
["numpy", "deprecate_with_doc"] => Replacement {
|
||||||
existing: "deprecate_with_doc",
|
existing: "deprecate_with_doc",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Emit `DeprecationWarning` with `warnings.warn` directly, or use `typing.deprecated`."),
|
guideline: Some("Emit `DeprecationWarning` with `warnings.warn` directly, or use `typing.deprecated`."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "disp"] => Some(Replacement {
|
["numpy", "disp"] => Replacement {
|
||||||
existing: "disp",
|
existing: "disp",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use a dedicated print function instead."),
|
guideline: Some("Use a dedicated print function instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "fastCopyAndTranspose"] => Some(Replacement {
|
["numpy", "fastCopyAndTranspose"] => Replacement {
|
||||||
existing: "fastCopyAndTranspose",
|
existing: "fastCopyAndTranspose",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use `arr.T.copy()` instead."),
|
guideline: Some("Use `arr.T.copy()` instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "find_common_type"] => Some(Replacement {
|
["numpy", "find_common_type"] => Replacement {
|
||||||
existing: "find_common_type",
|
existing: "find_common_type",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use `numpy.promote_types` or `numpy.result_type` instead. To achieve semantics for the `scalar_types` argument, use `numpy.result_type` and pass the Python values `0`, `0.0`, or `0j`."),
|
guideline: Some("Use `numpy.promote_types` or `numpy.result_type` instead. To achieve semantics for the `scalar_types` argument, use `numpy.result_type` and pass the Python values `0`, `0.0`, or `0j`."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "get_array_wrap"] => Some(Replacement {
|
["numpy", "get_array_wrap"] => Replacement {
|
||||||
existing: "get_array_wrap",
|
existing: "get_array_wrap",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: None,
|
guideline: None,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "float_"] => Some(Replacement {
|
["numpy", "float_"] => Replacement {
|
||||||
existing: "float_",
|
existing: "float_",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "float64",
|
name: "float64",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "geterrobj"] => Some(Replacement {
|
["numpy", "geterrobj"] => Replacement {
|
||||||
existing: "geterrobj",
|
existing: "geterrobj",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use the `np.errstate` context manager instead."),
|
guideline: Some("Use the `np.errstate` context manager instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "in1d"] => Some(Replacement {
|
["numpy", "in1d"] => Replacement {
|
||||||
existing: "in1d",
|
existing: "in1d",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "isin",
|
name: "isin",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "INF"] => Some(Replacement {
|
["numpy", "INF"] => Replacement {
|
||||||
existing: "INF",
|
existing: "INF",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "inf",
|
name: "inf",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "Inf"] => Some(Replacement {
|
["numpy", "Inf"] => Replacement {
|
||||||
existing: "Inf",
|
existing: "Inf",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "inf",
|
name: "inf",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "Infinity"] => Some(Replacement {
|
["numpy", "Infinity"] => Replacement {
|
||||||
existing: "Infinity",
|
existing: "Infinity",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "inf",
|
name: "inf",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "infty"] => Some(Replacement {
|
["numpy", "infty"] => Replacement {
|
||||||
existing: "infty",
|
existing: "infty",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "inf",
|
name: "inf",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "issctype"] => Some(Replacement {
|
["numpy", "issctype"] => Replacement {
|
||||||
existing: "issctype",
|
existing: "issctype",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: None,
|
guideline: None,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "issubclass_"] => Some(Replacement {
|
["numpy", "issubclass_"] => Replacement {
|
||||||
existing: "issubclass_",
|
existing: "issubclass_",
|
||||||
details: Details::AutoPurePython {
|
details: Details::AutoPurePython {
|
||||||
python_expr: "issubclass",
|
python_expr: "issubclass",
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "issubsctype"] => Some(Replacement {
|
["numpy", "issubsctype"] => Replacement {
|
||||||
existing: "issubsctype",
|
existing: "issubsctype",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "issubdtype",
|
name: "issubdtype",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "mat"] => Some(Replacement {
|
["numpy", "mat"] => Replacement {
|
||||||
existing: "mat",
|
existing: "mat",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "asmatrix",
|
name: "asmatrix",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "maximum_sctype"] => Some(Replacement {
|
["numpy", "maximum_sctype"] => Replacement {
|
||||||
existing: "maximum_sctype",
|
existing: "maximum_sctype",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: None,
|
guideline: None,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", existing @ ("NaN" | "NAN")] => Some(Replacement {
|
["numpy", existing @ ("NaN" | "NAN")] => Replacement {
|
||||||
existing,
|
existing,
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "nan",
|
name: "nan",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "nbytes"] => Some(Replacement {
|
["numpy", "nbytes"] => Replacement {
|
||||||
existing: "nbytes",
|
existing: "nbytes",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use `np.dtype(<dtype>).itemsize` instead."),
|
guideline: Some("Use `np.dtype(<dtype>).itemsize` instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "NINF"] => Some(Replacement {
|
["numpy", "NINF"] => Replacement {
|
||||||
existing: "NINF",
|
existing: "NINF",
|
||||||
details: Details::AutoPurePython {
|
details: Details::AutoPurePython {
|
||||||
python_expr: "-np.inf",
|
python_expr: "-np.inf",
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "NZERO"] => Some(Replacement {
|
["numpy", "NZERO"] => Replacement {
|
||||||
existing: "NZERO",
|
existing: "NZERO",
|
||||||
details: Details::AutoPurePython {
|
details: Details::AutoPurePython {
|
||||||
python_expr: "-0.0",
|
python_expr: "-0.0",
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "longcomplex"] => Some(Replacement {
|
["numpy", "longcomplex"] => Replacement {
|
||||||
existing: "longcomplex",
|
existing: "longcomplex",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "clongdouble",
|
name: "clongdouble",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "longfloat"] => Some(Replacement {
|
["numpy", "longfloat"] => Replacement {
|
||||||
existing: "longfloat",
|
existing: "longfloat",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "longdouble",
|
name: "longdouble",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "lookfor"] => Some(Replacement {
|
["numpy", "lookfor"] => Replacement {
|
||||||
existing: "lookfor",
|
existing: "lookfor",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Search NumPy’s documentation directly."),
|
guideline: Some("Search NumPy’s documentation directly."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "obj2sctype"] => Some(Replacement {
|
["numpy", "obj2sctype"] => Replacement {
|
||||||
existing: "obj2sctype",
|
existing: "obj2sctype",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: None,
|
guideline: None,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "PINF"] => Some(Replacement {
|
["numpy", "PINF"] => Replacement {
|
||||||
existing: "PINF",
|
existing: "PINF",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "inf",
|
name: "inf",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "product"] => Some(Replacement {
|
["numpy", "product"] => Replacement {
|
||||||
existing: "product",
|
existing: "product",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "prod",
|
name: "prod",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "PZERO"] => Some(Replacement {
|
["numpy", "PZERO"] => Replacement {
|
||||||
existing: "PZERO",
|
existing: "PZERO",
|
||||||
details: Details::AutoPurePython { python_expr: "0.0" },
|
details: Details::AutoPurePython { python_expr: "0.0" },
|
||||||
}),
|
},
|
||||||
["numpy", "recfromcsv"] => Some(Replacement {
|
["numpy", "recfromcsv"] => Replacement {
|
||||||
existing: "recfromcsv",
|
existing: "recfromcsv",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use `np.genfromtxt` with comma delimiter instead."),
|
guideline: Some("Use `np.genfromtxt` with comma delimiter instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "recfromtxt"] => Some(Replacement {
|
["numpy", "recfromtxt"] => Replacement {
|
||||||
existing: "recfromtxt",
|
existing: "recfromtxt",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use `np.genfromtxt` instead."),
|
guideline: Some("Use `np.genfromtxt` instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "round_"] => Some(Replacement {
|
["numpy", "round_"] => Replacement {
|
||||||
existing: "round_",
|
existing: "round_",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "round",
|
name: "round",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "safe_eval"] => Some(Replacement {
|
["numpy", "safe_eval"] => Replacement {
|
||||||
existing: "safe_eval",
|
existing: "safe_eval",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "ast",
|
path: "ast",
|
||||||
name: "literal_eval",
|
name: "literal_eval",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "sctype2char"] => Some(Replacement {
|
["numpy", "sctype2char"] => Replacement {
|
||||||
existing: "sctype2char",
|
existing: "sctype2char",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: None,
|
guideline: None,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "sctypes"] => Some(Replacement {
|
["numpy", "sctypes"] => Replacement {
|
||||||
existing: "sctypes",
|
existing: "sctypes",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: None,
|
guideline: None,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "seterrobj"] => Some(Replacement {
|
["numpy", "seterrobj"] => Replacement {
|
||||||
existing: "seterrobj",
|
existing: "seterrobj",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use the `np.errstate` context manager instead."),
|
guideline: Some("Use the `np.errstate` context manager instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "set_string_function"] => Some(Replacement {
|
["numpy", "set_string_function"] => Replacement {
|
||||||
existing: "set_string_function",
|
existing: "set_string_function",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use `np.set_printoptions` for custom printing of NumPy objects."),
|
guideline: Some("Use `np.set_printoptions` for custom printing of NumPy objects."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "singlecomplex"] => Some(Replacement {
|
["numpy", "singlecomplex"] => Replacement {
|
||||||
existing: "singlecomplex",
|
existing: "singlecomplex",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "complex64",
|
name: "complex64",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "string_"] => Some(Replacement {
|
["numpy", "string_"] => Replacement {
|
||||||
existing: "string_",
|
existing: "string_",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "bytes_",
|
name: "bytes_",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "sometrue"] => Some(Replacement {
|
["numpy", "sometrue"] => Replacement {
|
||||||
existing: "sometrue",
|
existing: "sometrue",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "any",
|
name: "any",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "source"] => Some(Replacement {
|
["numpy", "source"] => Replacement {
|
||||||
existing: "source",
|
existing: "source",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "inspect",
|
path: "inspect",
|
||||||
name: "getsource",
|
name: "getsource",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "tracemalloc_domain"] => Some(Replacement {
|
["numpy", "tracemalloc_domain"] => Replacement {
|
||||||
existing: "tracemalloc_domain",
|
existing: "tracemalloc_domain",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.lib",
|
path: "numpy.lib",
|
||||||
name: "tracemalloc_domain",
|
name: "tracemalloc_domain",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "trapz"] => Some(Replacement {
|
["numpy", "trapz"] => Replacement {
|
||||||
existing: "trapz",
|
existing: "trapz",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "trapezoid",
|
name: "trapezoid",
|
||||||
compatibility: Compatibility::Breaking,
|
compatibility: Compatibility::Breaking,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "unicode_"] => Some(Replacement {
|
["numpy", "unicode_"] => Replacement {
|
||||||
existing: "unicode_",
|
existing: "unicode_",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "str_",
|
name: "str_",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "who"] => Some(Replacement {
|
["numpy", "who"] => Replacement {
|
||||||
existing: "who",
|
existing: "who",
|
||||||
details: Details::Manual {
|
details: Details::Manual {
|
||||||
guideline: Some("Use an IDE variable explorer or `locals()` instead."),
|
guideline: Some("Use an IDE variable explorer or `locals()` instead."),
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "row_stack"] => Some(Replacement {
|
["numpy", "row_stack"] => Replacement {
|
||||||
existing: "row_stack",
|
existing: "row_stack",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy",
|
path: "numpy",
|
||||||
name: "vstack",
|
name: "vstack",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "AxisError"] => Some(Replacement {
|
["numpy", "AxisError"] => Replacement {
|
||||||
existing: "AxisError",
|
existing: "AxisError",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.exceptions",
|
path: "numpy.exceptions",
|
||||||
name: "AxisError",
|
name: "AxisError",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "ComplexWarning"] => Some(Replacement {
|
["numpy", "ComplexWarning"] => Replacement {
|
||||||
existing: "ComplexWarning",
|
existing: "ComplexWarning",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.exceptions",
|
path: "numpy.exceptions",
|
||||||
name: "ComplexWarning",
|
name: "ComplexWarning",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "DTypePromotionError"] => Some(Replacement {
|
["numpy", "DTypePromotionError"] => Replacement {
|
||||||
existing: "DTypePromotionError",
|
existing: "DTypePromotionError",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.exceptions",
|
path: "numpy.exceptions",
|
||||||
name: "DTypePromotionError",
|
name: "DTypePromotionError",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "ModuleDeprecationWarning"] => Some(Replacement {
|
["numpy", "ModuleDeprecationWarning"] => Replacement {
|
||||||
existing: "ModuleDeprecationWarning",
|
existing: "ModuleDeprecationWarning",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.exceptions",
|
path: "numpy.exceptions",
|
||||||
name: "ModuleDeprecationWarning",
|
name: "ModuleDeprecationWarning",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "RankWarning"] => Some(Replacement {
|
["numpy", "RankWarning"] => Replacement {
|
||||||
existing: "RankWarning",
|
existing: "RankWarning",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.exceptions",
|
path: "numpy.exceptions",
|
||||||
name: "RankWarning",
|
name: "RankWarning",
|
||||||
compatibility: Compatibility::Breaking,
|
compatibility: Compatibility::Breaking,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "TooHardError"] => Some(Replacement {
|
["numpy", "TooHardError"] => Replacement {
|
||||||
existing: "TooHardError",
|
existing: "TooHardError",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.exceptions",
|
path: "numpy.exceptions",
|
||||||
name: "TooHardError",
|
name: "TooHardError",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "VisibleDeprecationWarning"] => Some(Replacement {
|
["numpy", "VisibleDeprecationWarning"] => Replacement {
|
||||||
existing: "VisibleDeprecationWarning",
|
existing: "VisibleDeprecationWarning",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.exceptions",
|
path: "numpy.exceptions",
|
||||||
name: "VisibleDeprecationWarning",
|
name: "VisibleDeprecationWarning",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "compare_chararrays"] => Some(Replacement {
|
["numpy", "compare_chararrays"] => Replacement {
|
||||||
existing: "compare_chararrays",
|
existing: "compare_chararrays",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.char",
|
path: "numpy.char",
|
||||||
name: "compare_chararrays",
|
name: "compare_chararrays",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "chararray"] => Some(Replacement {
|
["numpy", "chararray"] => Replacement {
|
||||||
existing: "chararray",
|
existing: "chararray",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.char",
|
path: "numpy.char",
|
||||||
name: "chararray",
|
name: "chararray",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
["numpy", "format_parser"] => Some(Replacement {
|
["numpy", "format_parser"] => Replacement {
|
||||||
existing: "format_parser",
|
existing: "format_parser",
|
||||||
details: Details::AutoImport {
|
details: Details::AutoImport {
|
||||||
path: "numpy.rec",
|
path: "numpy.rec",
|
||||||
name: "format_parser",
|
name: "format_parser",
|
||||||
compatibility: Compatibility::BackwardsCompatible,
|
compatibility: Compatibility::BackwardsCompatible,
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
_ => None,
|
_ => return,
|
||||||
});
|
};
|
||||||
|
|
||||||
if let Some(replacement) = maybe_replacement {
|
|
||||||
let mut diagnostic = Diagnostic::new(
|
let mut diagnostic = Diagnostic::new(
|
||||||
Numpy2Deprecation {
|
Numpy2Deprecation {
|
||||||
existing: replacement.existing.to_string(),
|
existing: replacement.existing.to_string(),
|
||||||
|
@ -687,9 +690,7 @@ pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) {
|
||||||
Compatibility::BackwardsCompatible => {
|
Compatibility::BackwardsCompatible => {
|
||||||
Fix::safe_edits(import_edit, [replacement_edit])
|
Fix::safe_edits(import_edit, [replacement_edit])
|
||||||
}
|
}
|
||||||
Compatibility::Breaking => {
|
Compatibility::Breaking => Fix::unsafe_edits(import_edit, [replacement_edit]),
|
||||||
Fix::unsafe_edits(import_edit, [replacement_edit])
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -699,5 +700,4 @@ pub(crate) fn numpy_2_0_deprecation(checker: &mut Checker, expr: &Expr) {
|
||||||
Details::Manual { guideline: _ } => {}
|
Details::Manual { guideline: _ } => {}
|
||||||
};
|
};
|
||||||
checker.diagnostics.push(diagnostic);
|
checker.diagnostics.push(diagnostic);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue