Create rule S6730: Deprecated NumPy aliases of built-in types should not be used (#2970)
You can preview this rule [here](https://sonarsource.github.io/rspec/#/rspec/S6730/python) (updated a few minutes after each push). ## Review A dedicated reviewer checked the rule description successfully for: - [ ] logical errors and incorrect information - [ ] information gaps and missing content - [ ] text style and tone - [ ] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule) --------- Co-authored-by: guillaume-dequenne-sonarsource <guillaume-dequenne-sonarsource@users.noreply.github.com> Co-authored-by: David Kunzmann <david.kunzmann@sonarsource.com>
This commit is contained in:
parent
4a8cbac06e
commit
8bbfc36d29
2
rules/S6730/metadata.json
Normal file
2
rules/S6730/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
25
rules/S6730/python/metadata.json
Normal file
25
rules/S6730/python/metadata.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"title": "Deprecated NumPy aliases of built-in types should not be used",
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "5min"
|
||||
},
|
||||
"tags": [
|
||||
"numpy",
|
||||
"data-science"
|
||||
],
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-6730",
|
||||
"sqKey": "S6730",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": ["Sonar way"],
|
||||
"quickfix": "unknown",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "MEDIUM"
|
||||
},
|
||||
"attribute": "CONVENTIONAL"
|
||||
}
|
||||
}
|
53
rules/S6730/python/rule.adoc
Normal file
53
rules/S6730/python/rule.adoc
Normal file
@ -0,0 +1,53 @@
|
||||
This rule raises an issue when a deprecated Numpy alias of a built-in type is used.
|
||||
|
||||
== Why is this an issue?
|
||||
|
||||
In NumPy, some built-in types such as `int` have aliases in the form of `numpy.int`. However, these aliases have been deprecated and should not be used anymore.
|
||||
|
||||
The following deprecated aliases should be replaced with their built-in alternatives:
|
||||
|
||||
[frame=all]
|
||||
[cols="^1,^1"]
|
||||
|===
|
||||
|Deprecated name|Equivalent built-in type
|
||||
|
||||
|numpy.bool|bool
|
||||
|numpy.int|int
|
||||
|numpy.float|float
|
||||
|numpy.complex|complex
|
||||
|numpy.object|object
|
||||
|numpy.str|str
|
||||
|numpy.long|int
|
||||
|numpy.unicode|str
|
||||
|===
|
||||
|
||||
== How to fix it
|
||||
|
||||
To fix this issue, make sure to replace deprecated NumPy type aliases with their corresponding built-in types.
|
||||
|
||||
=== Code examples
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,python,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
import numpy as np
|
||||
def foo():
|
||||
x = np.int(42) # Noncompliant: deprecated type alias
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,python,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
import numpy as np
|
||||
def foo():
|
||||
x = 42 # Compliant
|
||||
----
|
||||
|
||||
|
||||
== Resources
|
||||
=== Documentation
|
||||
|
||||
* NumPy Documentation - https://numpy.org/devdocs/user/basics.types.html#basics-types[Data types]
|
||||
* NumPy Documentation - https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations[Deprecation of aliases of builtin types]
|
Loading…
x
Reference in New Issue
Block a user