mirror of
https://github.com/github/codeql.git
synced 2025-12-24 12:46:34 +01:00
Python: Stop py/import-deprecated-module from double alerting
This changes the location from the import statement, to the actual expression
This commit is contained in:
@@ -12,6 +12,10 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The module `name` was deprecated in Python version `major`.`minor`,
|
||||||
|
* and module `instead` should be used instead (or `instead = "no replacement"`)
|
||||||
|
*/
|
||||||
predicate deprecated_module(string name, string instead, int major, int minor) {
|
predicate deprecated_module(string name, string instead, int major, int minor) {
|
||||||
name = "posixfile" and instead = "email" and major = 1 and minor = 5
|
name = "posixfile" and instead = "email" and major = 1 and minor = 5
|
||||||
or
|
or
|
||||||
@@ -69,8 +73,8 @@ string replacement_message(string mod) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
from ImportExpr imp, Stmt s, Expr e
|
from ImportExpr imp, string name
|
||||||
where
|
where
|
||||||
s.getASubExpression() = e and
|
name = imp.getName() and
|
||||||
(e = imp or e.contains(imp))
|
deprecated_module(name, _, _, _)
|
||||||
select s, deprecation_message(imp.getName()) + replacement_message(imp.getName())
|
select imp, deprecation_message(name) + replacement_message(name)
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
| test.py:2:1:2:13 | Import | The rfc822 module was deprecated in version 2.3. Use email module instead. |
|
| test.py:2:8:2:13 | ImportExpr | The rfc822 module was deprecated in version 2.3. Use email module instead. |
|
||||||
| test.py:3:1:3:16 | Import | The posixfile module was deprecated in version 1.5. Use email module instead. |
|
| test.py:3:8:3:16 | ImportExpr | The posixfile module was deprecated in version 1.5. Use email module instead. |
|
||||||
| test.py:6:1:6:18 | ClassDef | The md5 module was deprecated in version 2.5. Use hashlib module instead. |
|
| test.py:8:16:8:18 | ImportExpr | The md5 module was deprecated in version 2.5. Use hashlib module instead. |
|
||||||
| test.py:7:5:7:18 | FunctionDef | The md5 module was deprecated in version 2.5. Use hashlib module instead. |
|
| test.py:14:10:14:12 | ImportExpr | The md5 module was deprecated in version 2.5. Use hashlib module instead. |
|
||||||
| test.py:8:9:8:18 | Import | The md5 module was deprecated in version 2.5. Use hashlib module instead. |
|
|
||||||
| test.py:14:5:14:23 | Import | The md5 module was deprecated in version 2.5. Use hashlib module instead. |
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import rfc822
|
import rfc822
|
||||||
import posixfile
|
import posixfile
|
||||||
|
|
||||||
# TODO: We should only report a bad import once
|
# We should only report a bad import once
|
||||||
class Foo(object):
|
class Foo(object):
|
||||||
def foo(self):
|
def foo(self):
|
||||||
import md5
|
import md5
|
||||||
|
|||||||
Reference in New Issue
Block a user