Skip to content

Commit 904a8b1

Browse files
committed
Python: Add consistency tests for class scope
1 parent a0e73ea commit 904a8b1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Originally we had module and functions as `DataFlowCallable``, and any call inside a
2+
# class scope would not have a result for getEnclosingCallable. Since this was only a
3+
# consistency error for calls, originally we added a new `DataFlowClassScope` only for
4+
# those classes that had a call in their scope. That's why all the class definitions in
5+
# this test do a call to the dummy function `func`.
6+
#
7+
# Note: this was shortsighted, since most DataFlow::Node use `getCallableScope` helper
8+
# to define their .getEnclosingCallable(), which picks the first DataFlowCallable to
9+
# contain the node. (so for some classes that would be DataFlowClassScope, and for some
10+
# it would be the module/function containing the class definition)
11+
12+
def func(*args, **kwargs):
13+
print("func()")
14+
15+
class Cls:
16+
func()
17+
class Inner:
18+
func()
19+
20+
def other_func():
21+
class Cls2:
22+
func()
23+
return Cls2
24+
25+
x = other_func()

python/ql/test/experimental/dataflow/consistency/dataflow-consistency.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
uniqueEnclosingCallable
22
uniqueCallEnclosingCallable
3+
| class_scope.py:16:5:16:10 | func() | Call should have one enclosing callable but has 0. |
4+
| class_scope.py:16:5:16:10 | func() | Call should have one enclosing callable but has 0. |
5+
| class_scope.py:18:9:18:14 | func() | Call should have one enclosing callable but has 0. |
6+
| class_scope.py:18:9:18:14 | func() | Call should have one enclosing callable but has 0. |
7+
| class_scope.py:22:9:22:14 | func() | Call should have one enclosing callable but has 0. |
8+
| class_scope.py:22:9:22:14 | func() | Call should have one enclosing callable but has 0. |
39
uniqueType
410
uniqueNodeLocation
511
missingLocation

0 commit comments

Comments
 (0)