Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a4ed69

Browse files
committed
Python: Make sure that all Modules and ModuleObjects (even unused packages) have a working toString().
1 parent 0b7d734 commit 4a4ed69

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

python/ql/src/semmle/python/Module.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ class Module extends Module_, Scope, AstNode {
99
override string toString() {
1010
result = this.getKind() + " " + this.getName()
1111
or
12-
/* No name is defined, which means that this is not on an import path. So it must be a script */
12+
/* No name is defined, which means that this module is not on an import path. So it must be a script */
1313
not exists(this.getName()) and not this.isPackage() and
1414
result = "Script " + this.getFile().getShortName()
15+
or
16+
/* Package missing name, so just use the path instead */
17+
not exists(this.getName()) and this.isPackage() and
18+
result = "Package at " + this.getPath().getAbsolutePath()
1519
}
1620

1721
/** This method will be deprecated in the next release. Please use `getEnclosingScope()` instead.

python/ql/src/semmle/python/types/ModuleObject.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ abstract class ModuleObject extends Object {
3232

3333
override string toString() {
3434
result = "Module " + this.getName()
35+
or
36+
not exists(this.getName()) and
37+
result = this.getModule().toString()
3538
}
3639

3740
/** Gets the named attribute of this module. Using attributeRefersTo() instead

0 commit comments

Comments
 (0)