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 @@
Functions/ModificationOfParameterWithDefault.ql
query: Functions/ModificationOfParameterWithDefault.ql

View File

@@ -1 +1,2 @@
Functions/DeprecatedSliceMethod.ql
query: Functions/DeprecatedSliceMethod.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Functions/ExplicitReturnInInit.ql
query: Functions/ExplicitReturnInInit.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Functions/InitIsGenerator.ql
query: Functions/InitIsGenerator.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1 @@
Functions/IterReturnsNonIterator.ql
query: Functions/IterReturnsNonIterator.ql

View File

@@ -1 +1,2 @@
Functions/OverlyComplexDelMethod.ql
query: Functions/OverlyComplexDelMethod.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Functions/SignatureOverriddenMethod.ql
query: Functions/SignatureOverriddenMethod.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Functions/SignatureSpecialMethods.ql
query: Functions/SignatureSpecialMethods.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1,7 +1,7 @@
class ExplicitReturnInInit(object):
def __init__(self):
return self
return self # $ Alert[py/explicit-return-in-init]
# These are OK
class ExplicitReturnNoneInInit(object):
@@ -29,7 +29,7 @@ class InitCallsInit(InitCallsError):
class InitIsGenerator(object):
def __init__(self):
def __init__(self): # $ Alert[py/init-method-is-generator]
yield self
# OK as it returns result of a call to super().__init__()
@@ -99,4 +99,4 @@ class InitReturnsCallResult6(object):
p = procedure_implicit_none()
else:
p = not_ok
return p()
return p() # $ Alert[py/explicit-return-in-init]

View File

@@ -92,13 +92,13 @@ def ok_to_ignore():
class DeprecatedSliceMethods(object):
def __getslice__(self, start, stop):
def __getslice__(self, start, stop): # $ Alert[py/deprecated-slice-method]
pass
def __setslice__(self, start, stop, value):
def __setslice__(self, start, stop, value): # $ Alert[py/deprecated-slice-method]
pass
def __delslice__(self, start, stop):
def __delslice__(self, start, stop): # $ Alert[py/deprecated-slice-method]
pass

View File

@@ -29,10 +29,10 @@ class Derived(Base):
def ok2(self, arg1, arg2 = 2, arg3 = 3):
return arg1, arg2, arg3
def grossly_wrong1(self, arg1):
def grossly_wrong1(self, arg1): # $ Alert[py/inheritance/signature-mismatch]
return arg1
def grossly_wrong2(self, arg1, arg2, arg3):
def grossly_wrong2(self, arg1, arg2, arg3): # $ Alert[py/inheritance/signature-mismatch]
return arg1, arg2, arg3
def strictly_wrong1(self, arg1):
@@ -56,19 +56,19 @@ class Special(object):
class WrongSpecials(object):
def __div__(self, x, y):
def __div__(self, x, y): # $ Alert[py/special-method-wrong-signature]
return self, x, y
def __mul__(self):
def __mul__(self): # $ Alert[py/special-method-wrong-signature]
return self
def __neg__(self, other):
def __neg__(self, other): # $ Alert[py/special-method-wrong-signature]
return self, other
def __exit__(self, arg0, arg1):
def __exit__(self, arg0, arg1): # $ Alert[py/special-method-wrong-signature]
return arg0 == arg1
def __repr__():
def __repr__(): # $ Alert[py/special-method-wrong-signature]
return ""
def __add__(self, other="Unused default"):
@@ -80,7 +80,7 @@ class WrongSpecials(object):
class OKSpecials(object):
def __del__():
def __del__(): # $ Alert[py/special-method-wrong-signature]
state = some_state()
def __del__(self):

View File

@@ -71,7 +71,7 @@ class AlmostIterable(object):
class MegaDel(object):
def __del__(self):
def __del__(self): # $ Alert[py/overly-complex-delete]
a = self.x + self.y
if a:
print(a)

View File

@@ -1 +1,2 @@
Functions/IterReturnsNonSelf.ql
query: Functions/IterReturnsNonSelf.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -2,7 +2,7 @@ class Bad1:
def __next__(self):
return 0
def __iter__(self): # BAD: Iter does not return self
def __iter__(self): # $ Alert # BAD: Iter does not return self
yield 0
class Good1:
@@ -48,6 +48,6 @@ class FalsePositive1:
self._it = iter(self)
return next(self._it)
def __iter__(self): # SPURIOUS, GOOD: implementation of next ensures the iterator is equivalent to the one returned by iter, but this is not detected.
def __iter__(self): # $ Alert # SPURIOUS, GOOD: implementation of next ensures the iterator is equivalent to the one returned by iter, but this is not detected.
yield 0
yield 0
yield 0

View File

@@ -1 +1,2 @@
Functions/IncorrectlyOverriddenMethod.ql
query: Functions/IncorrectlyOverriddenMethod.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Functions/IncorrectlySpecifiedOverriddenMethod.ql
query: Functions/IncorrectlySpecifiedOverriddenMethod.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Expressions/WrongNameForArgumentInCall.ql
query: Expressions/WrongNameForArgumentInCall.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Expressions/WrongNumberArgumentsInCall.ql
query: Expressions/WrongNumberArgumentsInCall.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -2,10 +2,10 @@
class Base(object):
def meth1(self):
def meth1(self): # $ Alert[py/inheritance/incorrect-overridden-signature]
pass
def meth2(self, spam):
def meth2(self, spam): # $ Alert[py/inheritance/incorrect-overridden-signature]
pass
def meth3(self):
@@ -13,18 +13,18 @@ class Base(object):
def foo(self):
self.meth1()
self.meth1(0)
self.meth2()
self.meth1(0) # $ Alert[py/call/wrong-arguments]
self.meth2() # $ Alert[py/call/wrong-arguments]
self.meth2(0)
self.meth1(spam="eggs")
self.meth1(spam="eggs") # $ Alert[py/call/wrong-named-argument]
self.meth2(spam="eggs")
class Derived(Base):
def meth1(self, spam): # $ Alert[py/inheritance/signature-mismatch] # Has 1 more arg, base called in Base.foo
def meth1(self, spam): # $ Alert[py/inheritance/signature-mismatch] Alert[py/inheritance/incorrect-overriding-signature] # Has 1 more arg, base called in Base.foo
pass
def meth2(self): # $ Alert[py/inheritance/signature-mismatch] # Has 1 fewer arg, base called in Base.foo
def meth2(self): # $ Alert[py/inheritance/signature-mismatch] Alert[py/inheritance/incorrect-overriding-signature] # Has 1 fewer arg, base called in Base.foo
pass
def meth3(self, eggs): # $ Alert[py/inheritance/signature-mismatch] # Has 1 more arg. Method is not called.
@@ -61,7 +61,7 @@ x.meth("hi")
class BlameBase(object):
def meth(self):
def meth(self): # $ Alert[py/inheritance/incorrect-overridden-signature]
pass
class Correct1(BlameBase):
@@ -109,7 +109,7 @@ class Base2:
self.meth1()
self.meth1(x=2)
self.meth3()
self.meth3(x=2)
self.meth3(x=2) # $ Alert[py/call/wrong-named-argument]
self.meth6(2, 3, 4)
self.meth7()
self.meth8(1,y=3)

View File

@@ -1 +1,2 @@
Functions/ConsistentReturns.ql
query: Functions/ConsistentReturns.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Functions/ReturnConsistentTupleSizes.ql
query: Functions/ReturnConsistentTupleSizes.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Functions/ReturnValueIgnored.ql
query: Functions/ReturnValueIgnored.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -1 +1,2 @@
Functions/UseImplicitNoneReturnValue.ql
query: Functions/UseImplicitNoneReturnValue.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -15,11 +15,11 @@ def ok2(x):
else:
return "Hi"
def cr1(x):
def cr1(x): # $ Alert[py/mixed-returns]
if x:
return 4
def cr2(x):
def cr2(x): # $ Alert[py/mixed-returns]
if x:
return 4
else:
@@ -74,7 +74,7 @@ def ok4(x):
def use_implicit_return_value(arg):
x = do_nothing()
x = do_nothing() # $ Alert[py/procedure-return-value-used]
return call_non_callable(arg)
#The return in the lambda is OK as it is auto-generated
@@ -156,9 +156,9 @@ def do_nothing():
def return_value_ignored():
ok2()
ok4()
sorted([1,2])
ok2() # $ Alert[py/ignored-return-value]
ok4() # $ Alert[py/ignored-return-value]
sorted([1,2]) # $ Alert[py/ignored-return-value]
d = {}
@@ -231,7 +231,7 @@ def mutli_return(arg):
if arg:
return do_something()
else:
return do_nothing()
return do_nothing() # $ Alert[py/procedure-return-value-used]
#Modification of parameter with default
@@ -303,7 +303,7 @@ y = foo()
# Returning tuples with different sizes
def returning_different_tuple_sizes(x):
def returning_different_tuple_sizes(x): # $ Alert[py/mixed-tuple-returns]
if x:
return 1,2
else:
@@ -326,14 +326,14 @@ def indirectly_returning_different_tuple_sizes(x): # OK, since we only look at l
return function_returning_2_tuple()
else:
return function_returning_3_tuple()
def mismatched_multi_assign(x):
a,b = returning_different_tuple_sizes(x)
return a,b
def ok_match(x): # FP
def ok_match(x): # $ SPURIOUS: Alert[py/mixed-returns] # FP
match x:
case True | 'true':
return 0
@@ -341,7 +341,7 @@ def ok_match(x): # FP
raise ValueError(x)
def ok_match2(x): # FP
def ok_match2(x): # $ SPURIOUS: Alert[py/mixed-returns] # FP
match x:
case None:
return 0