mirror of
https://github.com/github/codeql.git
synced 2025-12-22 11:46:32 +01:00
Python: Add variables regression test
As illustrated when running the python file, the non qualified reads in the `use` method all refer to the global variables, whereas `ex = func(baz)` are to the things defined on the class. The important part of the .expected changes is that the _global_ variable `bar` is used inside the function, whereas it's the local variable for `foo` (on class scope) that is used inside the function (which is wrong).
This commit is contained in:
@@ -1,3 +1,40 @@
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable MyClass | in_class.py:5:7:5:13 | MyClass |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable MyClass | in_class.py:30:6:30:12 | MyClass |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable NameError | in_class.py:17:16:17:24 | NameError |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable bar | in_class.py:2:1:2:3 | bar |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable bar | in_class.py:14:15:14:17 | bar |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable foo | in_class.py:1:1:1:3 | foo |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable mc | in_class.py:30:1:30:2 | mc |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable mc | in_class.py:32:1:32:2 | mc |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable mc | in_class.py:35:7:35:8 | mc |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable object | in_class.py:5:15:5:20 | object |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:9:9:9:13 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:12:9:12:13 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:13:9:13:13 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:14:9:14:13 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:16:13:16:17 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:20:9:20:13 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:21:9:21:13 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:22:9:22:13 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:25:9:25:13 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:31:1:31:5 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:34:1:34:5 | print |
|
||||
| in_class.py:0:0:0:0 | Module in_class | Global Variable print | in_class.py:35:1:35:5 | print |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable baz | in_class.py:6:5:6:7 | baz |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable baz | in_class.py:16:19:16:21 | baz |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable baz | in_class.py:28:15:28:17 | baz |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable ex | in_class.py:28:5:28:6 | ex |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable foo | in_class.py:8:9:8:11 | foo |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable foo | in_class.py:13:15:13:17 | foo |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable func | in_class.py:24:9:24:12 | func |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable func | in_class.py:28:10:28:13 | func |
|
||||
| in_class.py:5:1:5:22 | Class MyClass | Local Variable use | in_class.py:11:9:11:11 | use |
|
||||
| in_class.py:8:5:8:18 | Function foo | Local Variable self | in_class.py:8:13:8:16 | self |
|
||||
| in_class.py:11:5:11:18 | Function use | Local Variable self | in_class.py:11:13:11:16 | self |
|
||||
| in_class.py:11:5:11:18 | Function use | Local Variable self | in_class.py:21:15:21:18 | self |
|
||||
| in_class.py:11:5:11:18 | Function use | Local Variable self | in_class.py:22:15:22:18 | self |
|
||||
| in_class.py:24:5:24:18 | Function func | Local Variable arg | in_class.py:24:14:24:16 | arg |
|
||||
| in_class.py:24:5:24:18 | Function func | Local Variable arg | in_class.py:25:27:25:29 | arg |
|
||||
| test.py:0:0:0:0 | Module test | Global Variable C | test.py:30:7:30:7 | C |
|
||||
| test.py:0:0:0:0 | Module test | Global Variable base | test.py:30:9:30:12 | base |
|
||||
| test.py:0:0:0:0 | Module test | Global Variable func0 | test.py:5:5:5:9 | func0 |
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
| Local Variable baz | in_class.py:5:1:5:22 | Class MyClass | in_class.py:11:5:11:18 | Function use |
|
||||
| Local Variable foo | in_class.py:5:1:5:22 | Class MyClass | in_class.py:11:5:11:18 | Function use |
|
||||
| Local Variable local2 | test.py:15:1:15:12 | Function func2 | test.py:17:5:17:23 | Function inner1 |
|
||||
| Local Variable local4 | test.py:22:1:22:26 | Function func3 | test.py:24:5:24:22 | Function inner_outer |
|
||||
| Local Variable local4 | test.py:22:1:22:26 | Function func3 | test.py:25:9:25:27 | Function inner2 |
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
| Global Variable C | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable MyClass | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable NameError | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable __name__ | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable __name__ | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable __package__ | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable __package__ | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable bar | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable base | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable foo | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable func0 | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable func1 | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable func2 | test.py:0:0:0:0 | Module test |
|
||||
@@ -12,6 +18,9 @@
|
||||
| Global Variable global0 | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable global1 | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable global_local | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable mc | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable object | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable print | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable range | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable seq | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable use_in_loop | test.py:0:0:0:0 | Module test |
|
||||
|
||||
35
python/ql/test/library-tests/variables/scopes/in_class.py
Normal file
35
python/ql/test/library-tests/variables/scopes/in_class.py
Normal file
@@ -0,0 +1,35 @@
|
||||
foo = "foo"
|
||||
bar = "bar"
|
||||
|
||||
|
||||
class MyClass(object):
|
||||
baz = "baz"
|
||||
|
||||
def foo(self):
|
||||
print("foo()")
|
||||
|
||||
def use(self):
|
||||
print("! use()")
|
||||
print(foo)
|
||||
print(bar)
|
||||
try:
|
||||
print(baz)
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
print("=== access on self ===")
|
||||
print(self.foo)
|
||||
print(self.baz)
|
||||
|
||||
def func(arg):
|
||||
print("! func()", arg)
|
||||
return 42
|
||||
|
||||
ex = func(baz)
|
||||
|
||||
mc = MyClass()
|
||||
print()
|
||||
mc.use()
|
||||
|
||||
print("\n! mc.ex")
|
||||
print(mc.ex)
|
||||
@@ -2,7 +2,12 @@
|
||||
| Local Variable .0 | test.py:48:12:48:29 | Function listcomp | fast |
|
||||
| Local Variable .0 | test.py:52:5:52:25 | Function listcomp | fast |
|
||||
| Local Variable Local | test.py:38:1:38:18 | Function func4 | fast |
|
||||
| Local Variable arg | in_class.py:24:5:24:18 | Function func | fast |
|
||||
| Local Variable baz | in_class.py:5:1:5:22 | Class MyClass | name |
|
||||
| Local Variable class_local | test.py:30:1:30:14 | Class C | name |
|
||||
| Local Variable ex | in_class.py:5:1:5:22 | Class MyClass | name |
|
||||
| Local Variable foo | in_class.py:5:1:5:22 | Class MyClass | name |
|
||||
| Local Variable func | in_class.py:5:1:5:22 | Class MyClass | name |
|
||||
| Local Variable inner1 | test.py:15:1:15:12 | Function func2 | fast |
|
||||
| Local Variable inner2 | test.py:24:5:24:22 | Function inner_outer | fast |
|
||||
| Local Variable inner_outer | test.py:22:1:22:26 | Function func3 | fast |
|
||||
@@ -22,10 +27,13 @@
|
||||
| Local Variable param4 | test.py:22:1:22:26 | Function func3 | fast |
|
||||
| Local Variable param5 | test.py:22:1:22:26 | Function func3 | fast |
|
||||
| Local Variable param6 | test.py:38:1:38:18 | Function func4 | fast |
|
||||
| Local Variable self | in_class.py:8:5:8:18 | Function foo | fast |
|
||||
| Local Variable self | in_class.py:11:5:11:18 | Function use | fast |
|
||||
| Local Variable self | test.py:34:5:34:19 | Function meth | fast |
|
||||
| Local Variable self | test.py:40:9:40:29 | Function meth_inner | fast |
|
||||
| Local Variable seq | test.py:44:1:44:15 | Function func5 | fast |
|
||||
| Local Variable seq | test.py:51:1:51:21 | Function use_in_loop | fast |
|
||||
| Local Variable use | in_class.py:5:1:5:22 | Class MyClass | name |
|
||||
| Local Variable v | test.py:51:1:51:21 | Function use_in_loop | fast |
|
||||
| Local Variable v | test.py:52:5:52:25 | Function listcomp | fast |
|
||||
| Local Variable x | test.py:45:12:45:27 | Function listcomp | fast |
|
||||
|
||||
@@ -1,3 +1,28 @@
|
||||
| in_class.py:5:15:5:20 | ControlFlowNode for object | global |
|
||||
| in_class.py:9:9:9:13 | ControlFlowNode for print | global |
|
||||
| in_class.py:12:9:12:13 | ControlFlowNode for print | global |
|
||||
| in_class.py:13:9:13:13 | ControlFlowNode for print | global |
|
||||
| in_class.py:13:15:13:17 | ControlFlowNode for foo | global |
|
||||
| in_class.py:14:9:14:13 | ControlFlowNode for print | global |
|
||||
| in_class.py:14:15:14:17 | ControlFlowNode for bar | global |
|
||||
| in_class.py:16:13:16:17 | ControlFlowNode for print | global |
|
||||
| in_class.py:16:19:16:21 | ControlFlowNode for baz | global |
|
||||
| in_class.py:17:16:17:24 | ControlFlowNode for NameError | global |
|
||||
| in_class.py:20:9:20:13 | ControlFlowNode for print | global |
|
||||
| in_class.py:21:9:21:13 | ControlFlowNode for print | global |
|
||||
| in_class.py:21:15:21:18 | ControlFlowNode for self | local |
|
||||
| in_class.py:22:9:22:13 | ControlFlowNode for print | global |
|
||||
| in_class.py:22:15:22:18 | ControlFlowNode for self | local |
|
||||
| in_class.py:25:9:25:13 | ControlFlowNode for print | global |
|
||||
| in_class.py:25:27:25:29 | ControlFlowNode for arg | local |
|
||||
| in_class.py:28:10:28:13 | ControlFlowNode for func | local |
|
||||
| in_class.py:28:15:28:17 | ControlFlowNode for baz | local |
|
||||
| in_class.py:30:6:30:12 | ControlFlowNode for MyClass | global |
|
||||
| in_class.py:31:1:31:5 | ControlFlowNode for print | global |
|
||||
| in_class.py:32:1:32:2 | ControlFlowNode for mc | global |
|
||||
| in_class.py:34:1:34:5 | ControlFlowNode for print | global |
|
||||
| in_class.py:35:1:35:5 | ControlFlowNode for print | global |
|
||||
| in_class.py:35:7:35:8 | ControlFlowNode for mc | global |
|
||||
| test.py:6:12:6:17 | ControlFlowNode for param0 | local |
|
||||
| test.py:6:21:6:26 | ControlFlowNode for param1 | local |
|
||||
| test.py:12:5:12:16 | ControlFlowNode for global_local | global |
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
| Global Variable C | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable MyClass | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable NameError | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable __name__ | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable __name__ | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable __package__ | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable __package__ | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable bar | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable base | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable foo | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable func0 | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable func1 | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable func2 | test.py:0:0:0:0 | Module test |
|
||||
@@ -12,6 +18,9 @@
|
||||
| Global Variable global0 | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable global1 | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable global_local | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable mc | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable object | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable print | in_class.py:0:0:0:0 | Module in_class |
|
||||
| Global Variable range | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable seq | test.py:0:0:0:0 | Module test |
|
||||
| Global Variable use_in_loop | test.py:0:0:0:0 | Module test |
|
||||
@@ -19,7 +28,12 @@
|
||||
| Local Variable .0 | test.py:48:12:48:29 | Function listcomp |
|
||||
| Local Variable .0 | test.py:52:5:52:25 | Function listcomp |
|
||||
| Local Variable Local | test.py:38:1:38:18 | Function func4 |
|
||||
| Local Variable arg | in_class.py:24:5:24:18 | Function func |
|
||||
| Local Variable baz | in_class.py:5:1:5:22 | Class MyClass |
|
||||
| Local Variable class_local | test.py:30:1:30:14 | Class C |
|
||||
| Local Variable ex | in_class.py:5:1:5:22 | Class MyClass |
|
||||
| Local Variable foo | in_class.py:5:1:5:22 | Class MyClass |
|
||||
| Local Variable func | in_class.py:5:1:5:22 | Class MyClass |
|
||||
| Local Variable inner1 | test.py:15:1:15:12 | Function func2 |
|
||||
| Local Variable inner2 | test.py:24:5:24:22 | Function inner_outer |
|
||||
| Local Variable inner_outer | test.py:22:1:22:26 | Function func3 |
|
||||
@@ -39,10 +53,13 @@
|
||||
| Local Variable param4 | test.py:22:1:22:26 | Function func3 |
|
||||
| Local Variable param5 | test.py:22:1:22:26 | Function func3 |
|
||||
| Local Variable param6 | test.py:38:1:38:18 | Function func4 |
|
||||
| Local Variable self | in_class.py:8:5:8:18 | Function foo |
|
||||
| Local Variable self | in_class.py:11:5:11:18 | Function use |
|
||||
| Local Variable self | test.py:34:5:34:19 | Function meth |
|
||||
| Local Variable self | test.py:40:9:40:29 | Function meth_inner |
|
||||
| Local Variable seq | test.py:44:1:44:15 | Function func5 |
|
||||
| Local Variable seq | test.py:51:1:51:21 | Function use_in_loop |
|
||||
| Local Variable use | in_class.py:5:1:5:22 | Class MyClass |
|
||||
| Local Variable v | test.py:51:1:51:21 | Function use_in_loop |
|
||||
| Local Variable v | test.py:52:5:52:25 | Function listcomp |
|
||||
| Local Variable x | test.py:45:12:45:27 | Function listcomp |
|
||||
|
||||
Reference in New Issue
Block a user