Python: Make sure packages have locations, so they can be displayed, even if those locations are meaningless.

This commit is contained in:
Mark Shannon
2019-02-21 12:53:59 +00:00
parent f5e419e774
commit c1b8f500c7
4 changed files with 14 additions and 4 deletions

View File

@@ -391,10 +391,14 @@ class Location extends @location {
/** Gets the file for this location */
File getFile() {
result = this.getPath()
}
private Container getPath() {
locations_default(this, result, _, _, _, _)
or
exists(Module m | locations_ast(this, m, _, _, _, _) |
result = m.getFile()
result = m.getPath()
)
}
@@ -423,7 +427,7 @@ class Location extends @location {
}
string toString() {
result = this.getFile().getName() + ":" + this.getStartLine().toString()
result = this.getPath().getName() + ":" + this.getStartLine().toString()
}
predicate hasLocationInfo(string filepath, int bl, int bc, int el, int ec) {

View File

@@ -115,6 +115,9 @@ class Module extends Module_, Scope, AstNode {
override Location getLocation() {
py_scope_location(result, this)
or
not py_scope_location(_, this) and
locations_ast(result, this, 0, 0, 0, 0)
}
/** Gets a child module or package of this package */

View File

@@ -21,16 +21,18 @@ class DerivedClass(BaseClass):
self.inst_attr
self.shadowing
#ODASA-3836
def comprehensions_and_generators(seq):
[y*y for y in seq]
(y*y for y in seq)
{y*y for y in seq}
{y:y*y for y in seq}
#ODASA-5391
@decorator(x)
class Decorated(object):
pass
d = Decorated()
import package