Skip to content

Commit c1b8f50

Browse files
committed
Python: Make sure packages have locations, so they can be displayed, even if those locations are meaningless.
1 parent f5e419e commit c1b8f50

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

python/ql/src/semmle/python/Files.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,14 @@ class Location extends @location {
391391

392392
/** Gets the file for this location */
393393
File getFile() {
394+
result = this.getPath()
395+
}
396+
397+
private Container getPath() {
394398
locations_default(this, result, _, _, _, _)
395399
or
396400
exists(Module m | locations_ast(this, m, _, _, _, _) |
397-
result = m.getFile()
401+
result = m.getPath()
398402
)
399403
}
400404

@@ -423,7 +427,7 @@ class Location extends @location {
423427
}
424428

425429
string toString() {
426-
result = this.getFile().getName() + ":" + this.getStartLine().toString()
430+
result = this.getPath().getName() + ":" + this.getStartLine().toString()
427431
}
428432

429433
predicate hasLocationInfo(string filepath, int bl, int bc, int el, int ec) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class Module extends Module_, Scope, AstNode {
115115

116116
override Location getLocation() {
117117
py_scope_location(result, this)
118+
or
119+
not py_scope_location(_, this) and
120+
locations_ast(result, this, 0, 0, 0, 0)
118121
}
119122

120123
/** Gets a child module or package of this package */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

python/ql/test/query-tests/analysis/Sanity/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ def method(self):
2121
self.inst_attr
2222
self.shadowing
2323

24-
#ODASA-3836
24+
2525
def comprehensions_and_generators(seq):
2626
[y*y for y in seq]
2727
(y*y for y in seq)
2828
{y*y for y in seq}
2929
{y:y*y for y in seq}
3030

31-
#ODASA-5391
31+
3232
@decorator(x)
3333
class Decorated(object):
3434
pass
3535

3636
d = Decorated()
37+
38+
import package

0 commit comments

Comments
 (0)