Convert Python qlref tests to inline expectations

This commit is contained in:
Owen Mansel-Chan
2026-06-15 11:06:48 +01:00
parent d6ade8fe95
commit 0c2df7c7e9
475 changed files with 1612 additions and 1382 deletions

View File

@@ -1 +1,2 @@
Variables/UndefinedExport.ql
query: Variables/UndefinedExport.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -19,12 +19,12 @@ def f(parameter):
helper # Explicitly as import
a # Imlicitly from ud_helper
defined
ug2 # ERROR
e # ERROR Defined in ud_helper, but not in __all__
ug2 # $ Alert[py/undefined-global-variable] # ERROR
e # $ Alert[py/undefined-global-variable] # ERROR Defined in ud_helper, but not in __all__
int
float
__file__ #OK all files have __file__ defined
__path__ #ERROR only modules have __path__ defined
__path__ # $ Alert[py/undefined-global-variable] #ERROR only modules have __path__ defined
len #Ok defined in builtins
monkey1 #Ok monkey-patched builtins
@@ -120,7 +120,7 @@ class Cls(object):
pfp3 += 1
def only_report_once():
ug3
ug3 # $ Alert[py/undefined-global-variable]
ug3
ug3
ug3

View File

@@ -1 +1,2 @@
Variables/UndefinedGlobal.ql
query: Variables/UndefinedGlobal.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -2,7 +2,7 @@
class C:
def m1(self):
y = ug1
y = ug1 # $ Alert[py/undefined-global-variable]
x = 1
return y
@@ -10,16 +10,16 @@ class C:
return p
def m3(self, x1):
return u2
return u2 # $ Alert[py/uninitialized-local-variable]
u2 = x1
def m4(self, x2):
if x2:
u3 = 1
return u3
return u3 # $ Alert[py/uninitialized-local-variable]
def f():
y = ug1
y = ug1 # $ Alert[py/undefined-global-variable]
x = 1
return y
@@ -34,7 +34,7 @@ def q(x4):
def j(u4):
del u4
return u4
return u4 # $ Alert[py/uninitialized-local-variable]
def k(x5):
x5 + 1
@@ -43,7 +43,7 @@ def k(x5):
def m(x6):
if x6:
u6 = 1
u6
u6 # $ Alert[py/uninitialized-local-variable]
#The following are not uninitialized, but unreachable.
u6
u6
@@ -66,13 +66,13 @@ def check_del(cond):
del u8
else:
pass
u8
u8 # $ Alert[py/uninitialized-local-variable]
if cond:
u9 = 1
del u9
else:
u9 = 2
u9
u9 # $ Alert[py/uninitialized-local-variable]
if cond:
x10 = 1
del x10
@@ -82,10 +82,10 @@ def check_del(cond):
x10
u11 = 1
del u11
u11
u11 # $ Alert[py/uninitialized-local-variable]
u12 = "hi"
del u12
del u12
del u12 # $ Alert[py/uninitialized-local-variable]
#x will always be defined.
def const_range():
@@ -116,7 +116,7 @@ def use_def_conditional(cond4, cond5):
u14 = 1
x16 = 2
if cond5:
return u14
return u14 # $ Alert[py/uninitialized-local-variable]
def init_and_set_flag_in_try(f):
@@ -148,7 +148,7 @@ def split_not_OK():
except:
cond = not False
if not not cond:
return u19
return u19 # $ Alert[py/uninitialized-local-variable]
def double_is_none(x):
if x is not None:
@@ -160,7 +160,7 @@ def double_is_none(x):
#ODASA-4241
def def_in_post_loop(seq):
j(x)
j(x) # $ Alert[py/uninitialized-local-variable]
x = []
for p in seq:
x = p
@@ -173,9 +173,9 @@ def f(cond1, cond2):
else:
y = 1
if cond2:
return x
return x # $ Alert[py/uninitialized-local-variable]
else:
return y
return y # $ Alert[py/uninitialized-local-variable]
def needs_splitting(var):
if var:

View File

@@ -1 +1,2 @@
Variables/UninitializedLocal.ql
query: Variables/UninitializedLocal.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,16 +1,16 @@
import dotted
__all__ = ["foo", "bar", "baz", "not_defined"]
__all__ = ["foo", "bar", "baz", "not_defined"] # $ Alert[py/undefined-export]
@dotted.decorator
def foo():
pass
@undotted_decorator
@undotted_decorator # $ Alert[py/undefined-global-variable]
def bar():
pass
@not_imported.but_dotted
@not_imported.but_dotted # $ Alert[py/undefined-global-variable]
def baz():
pass

View File

@@ -1,4 +1,4 @@
__all__ = ["foo", "bar", "baz", "quux", "blat", "frob", "nosuch", "i_got_it_elsewhere"]
__all__ = ["foo", "bar", "baz", "quux", "blat", "frob", "nosuch", "i_got_it_elsewhere"] # $ Alert[py/undefined-export]
with open("foo.txt") as f:
foo = f.read()

View File

@@ -8,7 +8,7 @@ def f(cond1, cond2):
except Exception:
if cond2:
var = 7
if var == 1:
if var == 1: # $ Alert[py/uninitialized-local-variable]
var = var + 1
elif var == 2:
var +- 3