Python: Make sure that all Modules and ModuleObjects (even unused packages) have a working toString().

This commit is contained in:
Mark Shannon
2019-06-11 14:34:16 +01:00
parent 0b7d73456e
commit 4a4ed69ade
2 changed files with 8 additions and 1 deletions

View File

@@ -9,9 +9,13 @@ class Module extends Module_, Scope, AstNode {
override string toString() {
result = this.getKind() + " " + this.getName()
or
/* No name is defined, which means that this is not on an import path. So it must be a script */
/* No name is defined, which means that this module is not on an import path. So it must be a script */
not exists(this.getName()) and not this.isPackage() and
result = "Script " + this.getFile().getShortName()
or
/* Package missing name, so just use the path instead */
not exists(this.getName()) and this.isPackage() and
result = "Package at " + this.getPath().getAbsolutePath()
}
/** This method will be deprecated in the next release. Please use `getEnclosingScope()` instead.

View File

@@ -32,6 +32,9 @@ abstract class ModuleObject extends Object {
override string toString() {
result = "Module " + this.getName()
or
not exists(this.getName()) and
result = this.getModule().toString()
}
/** Gets the named attribute of this module. Using attributeRefersTo() instead