Skip to content

Commit e5cd3e8

Browse files
committed
Python: nice locations for import aliases
These were computed wrongly before.
1 parent eac44e8 commit e5cd3e8

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
| import_statements.py | 1 | 6 | 1 | 33 |
22
| import_statements.py | 1 | 42 | 1 | 53 |
33
| import_statements.py | 2 | 6 | 2 | 41 |
4-
| import_statements.py | 2 | 60 | 2 | 76 |
54
| import_statements.py | 2 | 71 | 2 | 76 |
65
| import_statements.py | 3 | 6 | 3 | 42 |
76
| import_statements.py | 4 | 5 | 4 | 12 |
8-
| import_statements.py | 4 | -7 | 4 | 12 |

0 commit comments

Comments
 (0)