From 4a4ed69adee0d9cd75fdabe76fb84deb6beb7e4e Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Tue, 11 Jun 2019 14:34:16 +0100 Subject: [PATCH] Python: Make sure that all Modules and ModuleObjects (even unused packages) have a working toString(). --- python/ql/src/semmle/python/Module.qll | 6 +++++- python/ql/src/semmle/python/types/ModuleObject.qll | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/python/ql/src/semmle/python/Module.qll b/python/ql/src/semmle/python/Module.qll index 275071b2925..da655f033d1 100644 --- a/python/ql/src/semmle/python/Module.qll +++ b/python/ql/src/semmle/python/Module.qll @@ -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. diff --git a/python/ql/src/semmle/python/types/ModuleObject.qll b/python/ql/src/semmle/python/types/ModuleObject.qll index 64493e08552..9b671747361 100644 --- a/python/ql/src/semmle/python/types/ModuleObject.qll +++ b/python/ql/src/semmle/python/types/ModuleObject.qll @@ -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