@@ -4,47 +4,47 @@ predicate is_import_time(Stmt s) {
4
4
not s .getScope + ( ) instanceof Function
5
5
}
6
6
7
- PythonModuleObject module_imported_by ( PythonModuleObject m ) {
7
+ ModuleValue module_imported_by ( ModuleValue m ) {
8
8
exists ( Stmt imp |
9
9
result = stmt_imports ( imp ) and
10
- imp .getEnclosingModule ( ) = m .getModule ( ) and
10
+ imp .getEnclosingModule ( ) = m .getScope ( ) and
11
11
// Import must reach exit to be part of a cycle
12
12
imp .getAnEntryNode ( ) .getBasicBlock ( ) .reachesExit ( )
13
13
)
14
14
}
15
15
16
16
/** Is there a circular import of 'm1' beginning with 'm2'? */
17
- predicate circular_import ( PythonModuleObject m1 , PythonModuleObject m2 ) {
17
+ predicate circular_import ( ModuleValue m1 , ModuleValue m2 ) {
18
18
m1 != m2 and
19
19
m2 = module_imported_by ( m1 ) and m1 = module_imported_by + ( m2 )
20
20
}
21
21
22
- ModuleObject stmt_imports ( ImportingStmt s ) {
22
+ ModuleValue stmt_imports ( ImportingStmt s ) {
23
23
exists ( string name |
24
24
result .importedAs ( name ) and not name = "__main__" |
25
25
name = s .getAnImportedModuleName ( )
26
26
)
27
27
}
28
28
29
- predicate import_time_imported_module ( PythonModuleObject m1 , PythonModuleObject m2 , Stmt imp ) {
30
- imp .getEnclosingModule ( ) = m1 .getModule ( ) and
29
+ predicate import_time_imported_module ( ModuleValue m1 , ModuleValue m2 , Stmt imp ) {
30
+ imp .getEnclosingModule ( ) = m1 .getScope ( ) and
31
31
is_import_time ( imp ) and
32
32
m2 = stmt_imports ( imp )
33
33
}
34
34
35
35
/** Is there a cyclic import of 'm1' beginning with an import 'm2' at 'imp' where all the imports are top-level? */
36
- predicate import_time_circular_import ( PythonModuleObject m1 , PythonModuleObject m2 , Stmt imp ) {
36
+ predicate import_time_circular_import ( ModuleValue m1 , ModuleValue m2 , Stmt imp ) {
37
37
m1 != m2 and
38
- import_time_imported_module ( m1 , m2 , imp ) and
38
+ import_time_imported_module ( m1 , m2 , imp ) and
39
39
import_time_transitive_import ( m2 , _, m1 )
40
40
}
41
41
42
- predicate import_time_transitive_import ( PythonModuleObject base , Stmt imp , PythonModuleObject last ) {
42
+ predicate import_time_transitive_import ( ModuleValue base , Stmt imp , ModuleValue last ) {
43
43
last != base and
44
44
(
45
45
import_time_imported_module ( base , last , imp )
46
46
or
47
- exists ( PythonModuleObject mid |
47
+ exists ( ModuleValue mid |
48
48
import_time_transitive_import ( base , imp , mid ) and
49
49
import_time_imported_module ( mid , last , _)
50
50
)
@@ -56,11 +56,11 @@ predicate import_time_transitive_import(PythonModuleObject base, Stmt imp, Pytho
56
56
/**
57
57
* Returns import-time usages of module 'm' in module 'enclosing'
58
58
*/
59
- predicate import_time_module_use ( PythonModuleObject m , PythonModuleObject enclosing , Expr use , string attr ) {
59
+ predicate import_time_module_use ( ModuleValue m , ModuleValue enclosing , Expr use , string attr ) {
60
60
exists ( Expr mod |
61
- use .getEnclosingModule ( ) = enclosing .getModule ( ) and
61
+ use .getEnclosingModule ( ) = enclosing .getScope ( ) and
62
62
not use .getScope + ( ) instanceof Function
63
- and mod .refersTo ( m )
63
+ and mod .pointsTo ( m )
64
64
|
65
65
// either 'M.foo'
66
66
use .( Attribute ) .getObject ( ) = mod and use .( Attribute ) .getName ( ) = attr
@@ -74,14 +74,14 @@ predicate import_time_module_use(PythonModuleObject m, PythonModuleObject enclos
74
74
AttributeError at 'use' (in module 'other') caused by 'first.attr' not being defined as its definition can
75
75
occur after the import 'other' in 'first'.
76
76
*/
77
- predicate failing_import_due_to_cycle ( PythonModuleObject first , PythonModuleObject other , Stmt imp ,
77
+ predicate failing_import_due_to_cycle ( ModuleValue first , ModuleValue other , Stmt imp ,
78
78
ControlFlowNode defn , Expr use , string attr ) {
79
79
import_time_imported_module ( other , first , _) and
80
80
import_time_transitive_import ( first , imp , other ) and
81
81
import_time_module_use ( first , other , use , attr ) and
82
- exists ( ImportTimeScope n , SsaVariable v |
82
+ exists ( ImportTimeScope n , SsaVariable v |
83
83
defn = v .getDefinition ( ) and
84
- n = first .getModule ( ) and v .getVariable ( ) .getScope ( ) = n and v .getId ( ) = attr |
84
+ n = first .getScope ( ) and v .getVariable ( ) .getScope ( ) = n and v .getId ( ) = attr |
85
85
not defn .strictlyDominates ( imp .getAnEntryNode ( ) )
86
86
)
87
87
and not exists ( If i | i .isNameEqMain ( ) and i .contains ( use ) )
0 commit comments