Skip to content

Commit 820d8e7

Browse files
committed
Python: Remove points-to from Module
1 parent b93ce98 commit 820d8e7

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

python/ql/lib/LegacyPointsTo.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
private import python
2323
private import semmle.python.pointsto.PointsTo
24+
private import semmle.python.objects.Modules
2425

2526
/**
2627
* An extension of `ControlFlowNode` that provides points-to predicates.
@@ -191,3 +192,19 @@ class ExprWithPointsTo extends Expr {
191192

192193
override string getAQlClass() { none() }
193194
}
195+
196+
/**
197+
* An extension of `Module` that provides points-to related methods.
198+
*/
199+
class ModuleWithPointsTo extends Module {
200+
/** Gets a name exported by this module, that is the names that will be added to a namespace by 'from this-module import *' */
201+
string getAnExport() {
202+
py_exports(this, result)
203+
or
204+
exists(ModuleObjectInternal mod | mod.getSource() = this.getEntryNode() |
205+
mod.(ModuleValue).exports(result)
206+
)
207+
}
208+
209+
override string getAQlClass() { none() }
210+
}

python/ql/lib/semmle/python/Module.qll

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import python
2-
private import semmle.python.objects.Modules
32
private import semmle.python.internal.CachedStages
43

54
/**
@@ -66,15 +65,6 @@ class Module extends Module_, Scope, AstNode {
6665
/** Whether this module is a package initializer */
6766
predicate isPackageInit() { this.getName().matches("%\\_\\_init\\_\\_") and not this.isPackage() }
6867

69-
/** Gets a name exported by this module, that is the names that will be added to a namespace by 'from this-module import *' */
70-
string getAnExport() {
71-
py_exports(this, result)
72-
or
73-
exists(ModuleObjectInternal mod | mod.getSource() = this.getEntryNode() |
74-
mod.(ModuleValue).exports(result)
75-
)
76-
}
77-
7868
/** Gets the source file for this module */
7969
File getFile() { py_module_path(this, result) }
8070

python/ql/src/Variables/UnusedModuleVariable.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
import python
16+
private import LegacyPointsTo
1617
import Definition
1718

1819
/**
@@ -58,7 +59,7 @@ predicate unused_global(Name unused, GlobalVariable v) {
5859
// indirectly
5960
defn.getBasicBlock().reachesExit() and u.getScope() != unused.getScope()
6061
) and
61-
not unused.getEnclosingModule().getAnExport() = v.getId() and
62+
not unused.getEnclosingModule().(ModuleWithPointsTo).getAnExport() = v.getId() and
6263
not exists(unused.getParentNode().(ClassDef).getDefinedClass().getADecorator()) and
6364
not exists(unused.getParentNode().(FunctionDef).getDefinedFunction().getADecorator()) and
6465
unused.defines(v) and
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import python
2+
private import LegacyPointsTo
23

3-
from Module m
4+
from ModuleWithPointsTo m
45
select m.toString(), m.getAnExport().toString()

0 commit comments

Comments
 (0)