Skip to content

Commit 7f79043

Browse files
tausbnyoffRasmusWL
authored
Python: More review suggestions
I could have sworn I added all of them to the batch, but somehow these slipped through. Co-authored-by: yoff <[email protected]> Co-authored-by: Rasmus Wriedt Larsen <[email protected]>
1 parent 131fc98 commit 7f79043

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/ImportResolution.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module ImportResolution {
7878
)
7979
or
8080
exists(Alias a |
81-
defn.asExpr() = [a.getValue(), a.getValue().(ImportMember).getModule()] and
81+
defn.asExpr() = [a.getValue().(ImportExpr), a.getValue().(ImportMember).getModule()] and
8282
a.getAsname().(Name).getId() = name and
8383
defn.getScope() = m
8484
)

python/ql/test/experimental/import-resolution/importflow.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private class ImportConfiguration extends DataFlow::Configuration {
2727
class ResolutionTest extends InlineExpectationsTest {
2828
ResolutionTest() { this = "ResolutionTest" }
2929

30-
override string getARelevantTag() { result = "import" }
30+
override string getARelevantTag() { result = "prints" }
3131

3232
override predicate hasActualResult(Location location, string element, string tag, string value) {
3333
exists(DataFlow::PathNode source, DataFlow::PathNode sink, ImportConfiguration config |

python/ql/test/experimental/import-resolution/main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
#! /usr/bin/env python3
2+
"""
3+
A slightly complicated test setup. I wanted to both make sure I captured
4+
the semantics of Python and also the fact that the kinds of global flow
5+
we expect to see are indeed present.
6+
7+
The code is executable, and prints out both when the execution reaches
8+
certain files, and also what values are assigned to the various
9+
attributes that are referenced throughout the program. These values are
10+
validated in the test as well.
11+
12+
My original version used introspection to avoid referencing attributes
13+
directly (thus enabling better error diagnostics), but unfortunately
14+
that made it so that the model couldn't follow what was going on.
15+
16+
The current setup is a bit clunky (and Python's scoping rules makes it
17+
especially so -- cf. the explicit calls to `globals` and `locals`), but
18+
I think it does the job okay.
19+
"""
220

321
from __future__ import print_function
422
import sys

0 commit comments

Comments
 (0)