1212
1313import python
1414
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+ */
1619predicate 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
1821 or
1922 name = "gopherlib" and instead = "no replacement" and major = 2 and minor = 5
2023 or
@@ -34,40 +37,49 @@ predicate deprecated_module(string name, string instead, int major, int minor) {
3437 or
3538 name = "rotor" and instead = "no replacement" and major = 2 and minor = 4
3639 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
3841 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
4043 or
4144 name = "xreadlines" and instead = "no replacement" and major = 2 and minor = 3
4245 or
4346 name = "multifile" and instead = "email" and major = 2 and minor = 5
4447 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
4649 or
4750 name = "buildtools" and instead = "no replacement" and major = 2 and minor = 3
4851 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
5053 or
5154 name = "macfs" and instead = "no replacement" and major = 2 and minor = 3
5255 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
5457 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
5659}
5760
5861string 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+ )
6166}
6267
6368string 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+ )
6974}
7075
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