Skip to content

Commit d12743d

Browse files
authored
Merge pull request github#13941 from yoff/python/test-nice-location
Python: fix nice locations for import aliases
2 parents 061575f + d2a0b9a commit d12743d

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

python/ql/lib/analysis/DefinitionTracking.qll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,14 @@ class NiceLocationExpr extends Expr {
492492
// for `import xxx` or for `import xxx as yyy`.
493493
this.(ImportExpr).getLocation().hasLocationInfo(f, bl, bc, el, ec)
494494
or
495-
/* Show y for `y` in `from xxx import y` */
496-
exists(string name |
497-
name = this.(ImportMember).getName() and
495+
// Show y for `y` in `from xxx import y`
496+
// and y for `yyy as y` in `from xxx import yyy as y`.
497+
exists(string name, Alias alias |
498+
// This alias will always exist, as `from xxx import y`
499+
// is expanded to `from xxx imprt y as y`.
500+
this = alias.getValue() and
501+
name = alias.getAsname().(Name).getId()
502+
|
498503
this.(ImportMember).getLocation().hasLocationInfo(f, _, _, el, ec) and
499504
bl = el and
500505
bc = ec - name.length() + 1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: fix
3+
---
4+
* Fixed the computation of locations for imports with aliases in jump-to-definition.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from nova.api.openstack.placement import microversion
2+
from nova.api.openstack.placement.objects import resource_provider as rp_obj
3+
from nova.api.openstack.placement.policies import allocation_candidate as \
4+
policies
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| import_statements.py | 1 | 6 | 1 | 33 |
2+
| import_statements.py | 1 | 42 | 1 | 53 |
3+
| import_statements.py | 2 | 6 | 2 | 41 |
4+
| import_statements.py | 2 | 71 | 2 | 76 |
5+
| import_statements.py | 3 | 6 | 3 | 42 |
6+
| import_statements.py | 4 | 5 | 4 | 12 |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import python
2+
import analysis.DefinitionTracking
3+
4+
from NiceLocationExpr expr, string f, int bl, int bc, int el, int ec
5+
where expr.hasLocationInfo(f, bl, bc, el, ec)
6+
select f, bl, bc, el, ec

0 commit comments

Comments
 (0)