Skip to content

Commit a1769f8

Browse files
committed
Python: add default implementation of getName() and deprecate it
1 parent e721094 commit a1769f8

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

python/ql/lib/semmle/python/Files.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,11 @@ abstract class Container extends @container {
154154
*/
155155
string toString() { result = this.getAbsolutePath() }
156156

157-
/** Gets the name of this container */
158-
abstract string getName();
157+
/**
158+
* Gets the name of this container.
159+
* DEPRECATED: Use `getAbsolutePath` instead.
160+
*/
161+
deprecated string getName() { result = this.getAbsolutePath() }
159162

160163
/**
161164
* Gets the relative path of this file or folder from the root folder of the
@@ -327,7 +330,7 @@ abstract class Container extends @container {
327330
* paths. The list of paths is composed of the paths passed to the extractor and
328331
* `sys.path`.
329332
*/
330-
predicate isImportRoot(int n) { this.getName() = import_path_element(n) }
333+
predicate isImportRoot(int n) { this.getAbsolutePath() = import_path_element(n) }
331334

332335
/** Holds if this folder is the root folder for the standard library. */
333336
predicate isStdLibRoot(int major, int minor) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class PackageObject extends ModuleObject {
184184
Location getLocation() { none() }
185185

186186
override predicate hasLocationInfo(string path, int bl, int bc, int el, int ec) {
187-
path = this.getPath().getName() and
187+
path = this.getPath().getAbsolutePath() and
188188
bl = 0 and
189189
bc = 0 and
190190
el = 0 and

python/ql/src/analysis/Consistency.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ predicate file_consistency(string clsname, string problem, string what) {
259259
exists(Container f |
260260
clsname = f.getAQlClass() and
261261
uniqueness_error(count(f.toString()), "toString", problem) and
262-
what = "file " + f.getName()
262+
what = "file " + f.getAbsolutePath()
263263
)
264264
}
265265

python/ql/test/library-tests/PointsTo/general/interesting.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ predicate of_interest(ControlFlowNode n, int line) {
44
exists(Location l, File f | l = n.getLocation() |
55
line = l.getStartLine() and
66
f = l.getFile() and
7-
f.getName().matches("%test.py%") and
7+
f.getAbsolutePath().matches("%test.py%") and
88
exists(Comment c |
99
c.getLocation().getStartLine() < line and
1010
c.getLocation().getFile() = f

0 commit comments

Comments
 (0)