mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Python: Add ModuleValue::hasCompleteExportInfo
This commit is contained in:
@@ -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() }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user