Python: Add consistency tests for class scope

This commit is contained in:
Rasmus Wriedt Larsen
2023-11-06 15:15:07 +01:00
parent a0e73eaab0
commit 904a8b1ea9
2 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
# Originally we had module and functions as `DataFlowCallable``, and any call inside a
# class scope would not have a result for getEnclosingCallable. Since this was only a
# consistency error for calls, originally we added a new `DataFlowClassScope` only for
# those classes that had a call in their scope. That's why all the class definitions in
# this test do a call to the dummy function `func`.
#
# Note: this was shortsighted, since most DataFlow::Node use `getCallableScope` helper
# to define their .getEnclosingCallable(), which picks the first DataFlowCallable to
# contain the node. (so for some classes that would be DataFlowClassScope, and for some
# it would be the module/function containing the class definition)
def func(*args, **kwargs):
print("func()")
class Cls:
func()
class Inner:
func()
def other_func():
class Cls2:
func()
return Cls2
x = other_func()

View File

@@ -1,5 +1,11 @@
uniqueEnclosingCallable
uniqueCallEnclosingCallable
| class_scope.py:16:5:16:10 | func() | Call should have one enclosing callable but has 0. |
| class_scope.py:16:5:16:10 | func() | Call should have one enclosing callable but has 0. |
| class_scope.py:18:9:18:14 | func() | Call should have one enclosing callable but has 0. |
| class_scope.py:18:9:18:14 | func() | Call should have one enclosing callable but has 0. |
| class_scope.py:22:9:22:14 | func() | Call should have one enclosing callable but has 0. |
| class_scope.py:22:9:22:14 | func() | Call should have one enclosing callable but has 0. |
uniqueType
uniqueNodeLocation
missingLocation