Python: Add ModuleValue::hasCompleteExportInfo

This commit is contained in:
Rasmus Wriedt Larsen
2019-12-16 17:19:04 +01:00
parent 3ffea599f1
commit 5faa7e7127
3 changed files with 39 additions and 4 deletions

View File

@@ -71,6 +71,9 @@ abstract class ModuleObjectInternal extends ObjectInternal {
py_exports(this.getSourceModule(), name)
}
/** Whether the complete set of names "exported" by this module can be accurately determined */
abstract predicate hasCompleteExportInfo();
override predicate isNotSubscriptedType() { any() }
}
@@ -125,6 +128,10 @@ class BuiltinModuleObjectInternal extends ModuleObjectInternal, TBuiltinModuleOb
none()
}
override predicate hasCompleteExportInfo() {
any()
}
}
/** A class representing packages */
@@ -230,6 +237,12 @@ class PackageObjectInternal extends ModuleObjectInternal, TPackageObject {
exists(this.submodule(name))
}
override predicate hasCompleteExportInfo() {
not exists(this.getInitModule())
or
this.getInitModule().hasCompleteExportInfo()
}
}
/** A class representing Python modules */
@@ -300,6 +313,17 @@ class PythonModuleObjectInternal extends ModuleObjectInternal, TPythonModule {
)
}
override predicate hasCompleteExportInfo() {
exists(Module m |
m = this.getSourceModule() |
not exists(Call modify, Attribute attr, GlobalVariable all |
modify.getScope() = m and modify.getFunc() = attr and
all.getId() = "__all__" |
attr.getObject().(Name).uses(all)
)
)
}
}
/** A class representing a module that is missing from the DB, but inferred to exists from imports. */
@@ -354,6 +378,9 @@ class AbsentModuleObjectInternal extends ModuleObjectInternal, TAbsentModule {
none()
}
override predicate hasCompleteExportInfo() {
none()
}
}
/** A class representing an attribute of a missing module. */
@@ -453,4 +480,3 @@ class AbsentModuleAttributeObjectInternal extends ObjectInternal, TAbsentModuleA
override predicate isNotSubscriptedType() { any() }
}

View File

@@ -150,6 +150,11 @@ class ModuleValue extends Value {
this instanceof PackageObjectInternal
}
/** Whether the complete set of names "exported" by this module can be accurately determined */
predicate hasCompleteExportInfo() {
this.(ModuleObjectInternal).hasCompleteExportInfo()
}
}
module Module {

View File

@@ -83,9 +83,13 @@ abstract class ModuleObject extends Object {
predicate exports(string name) {
theModule().exports(name)
}
/** Whether the complete set of names "exported" by this module can be accurately determined */
abstract predicate exportsComplete();
/**
* Whether the complete set of names "exported" by this module can be accurately determined
*
* DEPRECATED: Use ModuleValue::hasCompleteExportInfo instead
*/
deprecated abstract predicate exportsComplete();
/** Gets the short name of the module. For example the short name of module x.y.z is 'z' */
string getShortName() {