12
12
13
13
import python
14
14
15
-
15
+ /**
16
+ * The module `name` was deprecated in Python version `major`.`minor`,
17
+ * and module `instead` should be used instead (or `instead = "no replacement"`)
18
+ */
16
19
predicate deprecated_module ( string name , string instead , int major , int minor ) {
17
- name = "posixfile" and instead = "email " and major = 1 and minor = 5
20
+ name = "posixfile" and instead = "fcntl " and major = 1 and minor = 5
18
21
or
19
22
name = "gopherlib" and instead = "no replacement" and major = 2 and minor = 5
20
23
or
@@ -34,40 +37,49 @@ predicate deprecated_module(string name, string instead, int major, int minor) {
34
37
or
35
38
name = "rotor" and instead = "no replacement" and major = 2 and minor = 4
36
39
or
37
- name = "statcache" and instead = "no replacement" and major = 2 and minor = 2
40
+ name = "statcache" and instead = "no replacement" and major = 2 and minor = 2
38
41
or
39
- name = "mpz" and instead = "a third party" and major = 2 and minor = 2
42
+ name = "mpz" and instead = "a third party" and major = 2 and minor = 2
40
43
or
41
44
name = "xreadlines" and instead = "no replacement" and major = 2 and minor = 3
42
45
or
43
46
name = "multifile" and instead = "email" and major = 2 and minor = 5
44
47
or
45
- name = "sets" and instead = "builtins" and major = 2 and minor = 6
48
+ name = "sets" and instead = "builtins" and major = 2 and minor = 6
46
49
or
47
50
name = "buildtools" and instead = "no replacement" and major = 2 and minor = 3
48
51
or
49
- name = "cfmfile" and instead = "no replacement" and major = 2 and minor = 4
52
+ name = "cfmfile" and instead = "no replacement" and major = 2 and minor = 4
50
53
or
51
54
name = "macfs" and instead = "no replacement" and major = 2 and minor = 3
52
55
or
53
- name = "md5" and instead = "hashlib" and major = 2 and minor = 5
56
+ name = "md5" and instead = "hashlib" and major = 2 and minor = 5
54
57
or
55
- name = "sha" and instead = "hashlib" and major = 2 and minor = 5
58
+ name = "sha" and instead = "hashlib" and major = 2 and minor = 5
56
59
}
57
60
58
61
string deprecation_message ( string mod ) {
59
- exists ( int major , int minor | deprecated_module ( mod , _, major , minor ) |
60
- result = "The " + mod + " module was deprecated in version " + major .toString ( ) + "." + minor .toString ( ) + "." )
62
+ exists ( int major , int minor | deprecated_module ( mod , _, major , minor ) |
63
+ result = "The " + mod + " module was deprecated in version " + major .toString ( ) + "." +
64
+ minor .toString ( ) + "."
65
+ )
61
66
}
62
67
63
68
string replacement_message ( string mod ) {
64
- exists ( string instead | deprecated_module ( mod , instead , _, _) |
65
- result = " Use " + instead + " module instead." and not instead = "no replacement"
66
- or
67
- result = "" and instead = "no replacement"
68
- )
69
+ exists ( string instead | deprecated_module ( mod , instead , _, _) |
70
+ result = " Use " + instead + " module instead." and not instead = "no replacement"
71
+ or
72
+ result = "" and instead = "no replacement"
73
+ )
69
74
}
70
75
71
- from ImportExpr imp , Stmt s , Expr e
72
- where s .getASubExpression ( ) = e and ( e = imp or e .contains ( imp ) )
73
- select s , deprecation_message ( imp .getName ( ) ) + replacement_message ( imp .getName ( ) )
76
+ from ImportExpr imp , string name , string instead
77
+ where
78
+ name = imp .getName ( ) and
79
+ deprecated_module ( name , instead , _, _) and
80
+ not exists ( Try try , ExceptStmt except | except = try .getAHandler ( )
81
+ |
82
+ except .getType ( ) .pointsTo ( ClassValue:: importError ( ) ) and
83
+ except .containsInScope ( imp )
84
+ )
85
+ select imp , deprecation_message ( name ) + replacement_message ( name )
0 commit comments