Undo conversion for queries that import LegacyPointsTo

This commit is contained in:
Owen Mansel-Chan
2026-06-19 11:18:19 +01:00
parent 5497f2c5fe
commit 451fc2e4e7
143 changed files with 287 additions and 358 deletions

View File

@@ -1,2 +1 @@
query: Classes/InconsistentMRO.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/InconsistentMRO.ql

View File

@@ -6,7 +6,7 @@ class X(object):
class Y(X):
pass
class Z(X, Y): # $ Alert
class Z(X, Y):
pass
class O:

View File

@@ -1,2 +1 @@
query: Classes/MaybeUndefinedClassAttribute.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/MaybeUndefinedClassAttribute.ql

View File

@@ -1,2 +1 @@
query: Classes/UndefinedClassAttribute.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/UndefinedClassAttribute.ql

View File

@@ -1,2 +1 @@
query: Exceptions/IllegalExceptionHandlerType.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Exceptions/IllegalExceptionHandlerType.ql

View File

@@ -1,2 +1 @@
query: Exceptions/IllegalRaise.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Exceptions/IllegalRaise.ql

View File

@@ -14,4 +14,4 @@ def raise_tuple(cond):
raise (Exception, "bananas", 17)
else:
#This is an error
raise (17, "bananas", Exception) # $ Alert[py/illegal-raise]
raise (17, "bananas", Exception)

View File

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

View File

@@ -62,14 +62,14 @@ print(average([1.0, 2.0]))
# This case is bad, and is a minimal obvious case that should be bad. It
# SHOULD be found by the query.
print(3 / 2) # $ Alert[py/truncated-division]
print(3 / 2)
# This case is bad. It uses indirect returns of integers through function calls
# to produce the problem. I
print(return_three() / return_two()) # $ Alert[py/truncated-division]
print(return_three() / return_two())

View File

@@ -1,2 +1 @@
query: Statements/IterableStringOrSequence.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Statements/IterableStringOrSequence.ql

View File

@@ -18,7 +18,7 @@ def f(x):
s = u"Hello World"
else:
s = [ u'Hello', u'World']
for thing in s: # $ Alert[py/iteration-string-and-sequence]
for thing in s:
print (thing)
import fake_six

View File

@@ -1,6 +1,6 @@
__all__ = [ "x", "y", "z", "module" ] # $ Alert[py/undefined-export]
__all__ = [ "x", "y", "z", "module" ]
x = 1
if 0:

View File

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

View File

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

View File

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

View File

@@ -1 +1 @@
__all__ = [ "module", "not_exists" ] # $ Alert[py/undefined-export]
__all__ = [ "module", "not_exists" ]

View File

@@ -1,2 +1 @@
query: Classes/DefineEqualsWhenAddingAttributes.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/DefineEqualsWhenAddingAttributes.ql

View File

@@ -9,7 +9,7 @@ class RedefineEquals:
def __eq__(self, other):
return other is "Tuesday"
class C(RedefineEquals): # $ Alert
class C(RedefineEquals):
def __init__(self, args):
self.a, self.b = args

View File

@@ -1,2 +1 @@
query: Classes/InconsistentMRO.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/InconsistentMRO.ql

View File

@@ -6,12 +6,12 @@ class X(object):
class Y(X):
pass
class Z(X, Y): # $ Alert
class Z(X, Y):
pass
class O:
pass
#This is OK in Python 2
class N(object, O): # $ Alert
class N(object, O):
pass

View File

@@ -1,2 +1 @@
query: Classes/MaybeUndefinedClassAttribute.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/MaybeUndefinedClassAttribute.ql

View File

@@ -1,2 +1 @@
query: Classes/UndefinedClassAttribute.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/UndefinedClassAttribute.ql

View File

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

View File

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

View File

@@ -9,8 +9,8 @@ f(1, 2, 3, kw1=1)
f(1, 2, kw1=1, kw2=2)
#Not OK
f(1, 2, 3, kw1=1, kw3=3) # $ Alert[py/call/wrong-named-argument]
f(1, 2, 3, kw3=3) # $ Alert[py/call/wrong-named-argument]
f(1, 2, 3, kw1=1, kw3=3)
f(1, 2, 3, kw3=3)
#ODASA-5897
@@ -21,4 +21,4 @@ def ok():
return analyze_member_access(msg, original=original, chk=chk)
def bad():
return analyze_member_access(msg, original, chk=chk) # $ Alert[py/call/wrong-arguments]
return analyze_member_access(msg, original, chk=chk)

View File

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

View File

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

View File

@@ -1,2 +1 @@
query: Statements/IterableStringOrSequence.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Statements/IterableStringOrSequence.ql

View File

@@ -1,2 +1 @@
query: Statements/NonIteratorInForLoop.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Statements/NonIteratorInForLoop.ql

View File

@@ -23,5 +23,5 @@ async def good():
yield x
async def bad():
async for x in MissingAiter(): # $ Alert[py/non-iterable-in-for-loop]
async for x in MissingAiter():
yield x

View File

@@ -18,7 +18,7 @@ def f(x):
s = u"Hello World"
else:
s = [ u'Hello', u'World']
for thing in s: # $ Alert[py/iteration-string-and-sequence]
for thing in s:
print (thing)
@@ -31,7 +31,7 @@ class Color(Enum):
def colors():
for color in Color:
print(color)
for color in 1: # $ Alert[py/non-iterable-in-for-loop]
for color in 1:
print(color)
colors()

View File

@@ -1,6 +1,6 @@
__all__ = [ "x", "y", "z", "module", "w" ] # $ Alert[py/undefined-export]
__all__ = [ "x", "y", "z", "module", "w" ]
x = 1
if 0:

View File

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

View File

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

View File

@@ -5,4 +5,4 @@ IntEnum._convert(
__name__,
lambda C: C.isupper() and C.startswith('AF_'))
__all__ = [ "Maybe", "Maybe_not" ] # $ Alert[py/undefined-export]
__all__ = [ "Maybe", "Maybe_not" ]

View File

@@ -1 +1 @@
__all__ = [ "module", "not_exists" ] # $ Alert[py/undefined-export]
__all__ = [ "module", "not_exists" ]

View File

@@ -1 +1 @@
query: ../CallGraph/InlineCallGraphTest.ql
../CallGraph/InlineCallGraphTest.ql

View File

@@ -1 +1 @@
query: ../CallGraph/InlineCallGraphTest.ql
../CallGraph/InlineCallGraphTest.ql

View File

@@ -1 +1 @@
query: ../CallGraph/InlineCallGraphTest.ql
../CallGraph/InlineCallGraphTest.ql

View File

@@ -1,2 +1 @@
query: Classes/WrongNameForArgumentInClassInstantiation.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/WrongNameForArgumentInClassInstantiation.ql

View File

@@ -1,2 +1 @@
query: Classes/WrongNumberArgumentsInClassInstantiation.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/WrongNumberArgumentsInClassInstantiation.ql

View File

@@ -34,22 +34,22 @@ class F7(object):
# Too few arguments
F0() # $ Alert[py/call/wrong-number-class-arguments]
F1() # $ Alert[py/call/wrong-number-class-arguments]
F2() # $ Alert[py/call/wrong-number-class-arguments]
F3() # $ Alert[py/call/wrong-number-class-arguments]
F4() # $ Alert[py/call/wrong-number-class-arguments]
F5() # $ Alert[py/call/wrong-number-class-arguments]
F6(1) # $ Alert[py/call/wrong-number-class-arguments]
F7(1,2) # $ Alert[py/call/wrong-number-class-arguments]
F0()
F1()
F2()
F3()
F4()
F5()
F6(1)
F7(1,2)
#Too many arguments
F0(1,2) # $ Alert[py/call/wrong-number-class-arguments]
F1(1,2,3) # $ Alert[py/call/wrong-number-class-arguments]
F5(1,2,3) # $ Alert[py/call/wrong-number-class-arguments]
F6(1,2,3) # $ Alert[py/call/wrong-number-class-arguments]
F6(1,2,3,4) # $ Alert[py/call/wrong-number-class-arguments]
F0(1,2)
F1(1,2,3)
F5(1,2,3)
F6(1,2,3)
F6(1,2,3,4)
#OK
@@ -62,9 +62,9 @@ F2(1,2,3,4,5,6)
#Illegal name
F0(y=1) # $ Alert[py/call/wrong-named-class-argument]
F1(z=1) # $ Alert[py/call/wrong-named-class-argument]
F2(x=0, y=1) # $ Alert[py/call/wrong-named-class-argument]
F0(y=1)
F1(z=1)
F2(x=0, y=1)
#Ok name
@@ -82,12 +82,12 @@ t3 = (1,2,3)
f(*t2)
#Too many
F6(*(1,2,3)) # $ Alert[py/call/wrong-number-class-arguments]
F6(*t3) # $ Alert[py/call/wrong-number-class-arguments]
F6(*(1,2,3))
F6(*t3)
#Ok
F6(**{'x':1, 'y':2})
#Illegal name
F6(**{'x':1, 'y':2, 'z':3}) # $ Alert[py/call/wrong-named-class-argument]
F6(**{'x':1, 'y':2, 'z':3})

View File

@@ -1,2 +1 @@
query: Classes/ConflictingAttributesInBaseClasses.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/ConflictingAttributesInBaseClasses.ql

View File

@@ -23,7 +23,7 @@ class CB2(Common):
return 0
class Conflict(CB1, CB2): # $ Alert
class Conflict(CB1, CB2):
pass
class Override1(Common):

View File

@@ -1,2 +1 @@
query: Classes/MutatingDescriptor.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/MutatingDescriptor.ql

View File

@@ -7,7 +7,7 @@ class MutatingDescriptor(object):
def __get__(self, obj, obj_type):
#Modified state is visible to all instances.
self.my_obj = obj # $ Alert
self.my_obj = obj
return self
def __call__(self, *args):
@@ -22,4 +22,4 @@ class MutatingDescriptor(object):
def not_ok(self, value):
#Modified state is visible to all instances.
self.my_obj = value # $ Alert
self.my_obj = value

View File

@@ -1,2 +1 @@
query: Classes/DefineEqualsWhenAddingAttributes.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/DefineEqualsWhenAddingAttributes.ql

View File

@@ -18,7 +18,7 @@ class Point(object):
def __hash__(self):
return hash((self._x, self._y))
class BadColorPoint(Point): # $ Alert
class BadColorPoint(Point):
def __init__(self, x, y, color):
Point.__init__(self, x, y)

View File

@@ -1,2 +1 @@
query: Classes/OverwritingAttributeInSuperClass.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/OverwritingAttributeInSuperClass.ql

View File

@@ -2,7 +2,7 @@
class C(object):
def __init__(self):
self.var = 0 # $ Alert
self.var = 0
class D(C):
@@ -20,4 +20,4 @@ class F(E):
def __init__(self):
E.__init__(self)
self.var = 1 # $ Alert
self.var = 1

View File

@@ -1,2 +1 @@
query: Classes/MaybeUndefinedClassAttribute.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/MaybeUndefinedClassAttribute.ql

View File

@@ -1,2 +1 @@
query: Classes/UndefinedClassAttribute.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Classes/UndefinedClassAttribute.ql

View File

@@ -21,10 +21,10 @@ class Attributes(object):
print (self.local_exists)
def neca1(self):
print (self.not_exists) # $ Alert[py/undefined-attribute]
print (self.not_exists)
def neca2(self):
print (self.may_exist) # $ Alert[py/maybe-undefined-attribute]
print (self.may_exist)
#This is OK
class SetViaDict(object):
@@ -106,7 +106,7 @@ class DecoratedInit(object):
class NoInit(object):
def use_y(self):
return self.y # $ Alert[py/undefined-attribute]
return self.y
#This is also OK
class SetLocally2(object):
@@ -181,7 +181,7 @@ class Test1(object):
self.return_queue = frame.method.queue
def use_it(self):
return self.return_queue # $ Alert[py/maybe-undefined-attribute]
return self.return_queue
#Check for FPs when overriding builtin methods
@@ -247,15 +247,15 @@ class Customer1(object):
class Odasa4619a(object):
def call(self):
host = self.glance_host # $ Alert[py/undefined-attribute]
port = self.glance_port # $ Alert[py/undefined-attribute]
host = self.glance_host
port = self.glance_port
class Odasa4619b(object):
def call(self):
host = self.glance_host # $ Alert[py/maybe-undefined-attribute]
port = self.glance_port # $ Alert[py/maybe-undefined-attribute]
host = self.glance_host
port = self.glance_port
@decorator
def foo(self):

View File

@@ -1,2 +1 @@
query: Exceptions/IllegalExceptionHandlerType.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Exceptions/IllegalExceptionHandlerType.ql

View File

@@ -1,2 +1 @@
query: Exceptions/IllegalRaise.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Exceptions/IllegalRaise.ql

View File

@@ -37,21 +37,21 @@ class NotException2(object):
pass
def illegal_raise_type():
raise NotException1 # $ Alert[py/illegal-raise]
raise NotException1
def illegal_raise_value1():
raise "Exception" # $ Alert[py/illegal-raise]
raise "Exception"
def illegal_raise_value2():
raise NotException2() # $ Alert[py/illegal-raise]
raise NotException2()
def illegal_handler():
try:
illegal_raise()
except NotException1: # $ Alert[py/useless-except]
except NotException1:
#Must do something
print("NotException1")
except NotException2: # $ Alert[py/useless-except]
except NotException2:
#Must do something
print("NotException2")
@@ -135,7 +135,7 @@ def a_number():
def illegal_handler2():
try:
illegal_raise()
except a_number(): # $ Alert[py/useless-except]
except a_number():
print ("Caught exception")
def stop_iter_ok(seq):

View File

@@ -11,9 +11,10 @@ def test():
try:
a = A()
raise a
except 42: # $ Alert[py/useless-except]
except 42:
#Some comment
pass
except A:
#Another comment
pass

View File

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

View File

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

View File

@@ -25,9 +25,9 @@ C.m1(1,2)
#But normal functions are treated normally
f0() # $ Alert[py/call/wrong-arguments]
f1(1) # $ Alert[py/call/wrong-arguments]
f0()
f1(1)
#As are normal methods
C().m0() # $ Alert[py/call/wrong-arguments]
C().m1(1) # $ Alert[py/call/wrong-arguments]
C().m0()
C().m1(1)

View File

@@ -26,22 +26,22 @@ def f7(x, y, z):
# Too few arguments
f0() # $ Alert[py/call/wrong-arguments]
f1() # $ Alert[py/call/wrong-arguments]
f2() # $ Alert[py/call/wrong-arguments]
f3() # $ Alert[py/call/wrong-arguments]
f4() # $ Alert[py/call/wrong-arguments]
f5() # $ Alert[py/call/wrong-arguments]
f6(1) # $ Alert[py/call/wrong-arguments]
f7(1,2) # $ Alert[py/call/wrong-arguments]
f0()
f1()
f2()
f3()
f4()
f5()
f6(1)
f7(1,2)
#Too many arguments
f0(1,2) # $ Alert[py/call/wrong-arguments]
f1(1,2,3) # $ Alert[py/call/wrong-arguments]
f5(1,2,3) # $ Alert[py/call/wrong-arguments]
f6(1,2,3) # $ Alert[py/call/wrong-arguments]
f6(1,2,3,4) # $ Alert[py/call/wrong-arguments]
f0(1,2)
f1(1,2,3)
f5(1,2,3)
f6(1,2,3)
f6(1,2,3,4)
#OK
@@ -54,9 +54,9 @@ f2(1,2,3,4,5,6)
#Illegal name
f0(y=1) # $ Alert[py/call/wrong-named-argument]
f1(z=1) # $ Alert[py/call/wrong-named-argument]
f2(x=0, y=1) # $ Alert[py/call/wrong-named-argument]
f0(y=1)
f1(z=1)
f2(x=0, y=1)
#Ok name
@@ -78,12 +78,12 @@ l1d()
l1d(1)
#Too many
l0(1) # $ Alert[py/call/wrong-arguments]
l1(1,2) # $ Alert[py/call/wrong-arguments]
l1d(1,2) # $ Alert[py/call/wrong-arguments]
l0(1)
l1(1,2)
l1d(1,2)
#Too few
l1() # $ Alert[py/call/wrong-arguments]
l1()
t2 = (1,2)
@@ -93,14 +93,14 @@ t3 = (1,2,3)
f(*t2)
#Too many
f6(*(1,2,3)) # $ Alert[py/call/wrong-arguments]
f6(*t3) # $ Alert[py/call/wrong-arguments]
f6(*(1,2,3))
f6(*t3)
#Ok
f6(**{'x':1, 'y':2})
#Illegal name
f6(**{'x':1, 'y':2, 'z':3}) # $ Alert[py/call/wrong-named-argument]
f6(**{'x':1, 'y':2, 'z':3})
#Theoretically -1 arguments required. Don't report
class C(object):
@@ -112,7 +112,7 @@ C().f()
#Too many and wrong name -- check only wrong name is flagged.
f1(x, y, z=1) # $ Alert[py/call/wrong-named-argument]
f1(x, y, z=1)
#Overriding and call is wrong.
@@ -127,5 +127,5 @@ class Eggs2(Eggs1):
pass
e = Eggs1() if cond else Eggs2()
e.spam(0) # $ Alert[py/call/wrong-arguments]
e.spam(0)

View File

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

View File

@@ -13,9 +13,9 @@ class IsCallable(object):
def call_non_callable(arg):
non = NonCallable()
non(arg) # $ Alert
()() # $ Alert
[]() # $ Alert
non(arg)
()()
[]()
dont_know = MaybeCallable()
dont_know() # Not a violation
ok = IsCallable()
@@ -23,7 +23,7 @@ def call_non_callable(arg):
if hasattr(non, "__call__"):
non(arg) # OK due to guard
if hasattr(non, "__init__"):
non(arg) # $ Alert # Not OK due to wrong guard
non(arg) # Not OK due to wrong guard
import six
@@ -44,7 +44,7 @@ def foo():
raise NotImplemented()
def bar():
return NotImplemented() # $ Alert
return NotImplemented()
# FP due to decorator
@@ -60,7 +60,7 @@ class Foo(object):
@some_decorator
@classmethod
def new_instance(cls, new_arg):
return cls(new_arg) # $ SPURIOUS: Alert # TODO: FP
return cls(new_arg) # TODO: FP
f1 = Foo(1)
f2 = f1.new_instance(2)

View File

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

View File

@@ -48,7 +48,7 @@ if "Hello World" is s: # $ Alert[py/comparison-using-is]
#This is OK in CPython, but may not be portable
s = str(7)
if "7" is s: # $ Alert[py/comparison-using-is-non-portable]
if "7" is s:
print ("OK")
#And some data flow

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,9 +8,9 @@ def dup_key():
def simple_func(*args, **kwrgs): pass
#Unnecessary lambdas
lambda arg0, arg1: simple_func(arg0, arg1) # $ Alert[py/unnecessary-lambda]
lambda arg0, *arg1: simple_func(arg0, *arg1) # $ Alert[py/unnecessary-lambda]
lambda arg0, **arg1: simple_func(arg0, **arg1) # $ Alert[py/unnecessary-lambda]
lambda arg0, arg1: simple_func(arg0, arg1)
lambda arg0, *arg1: simple_func(arg0, *arg1)
lambda arg0, **arg1: simple_func(arg0, **arg1)
# these lambdas are_ necessary
lambda arg0, arg1=1: simple_func(arg0, arg1)
lambda arg0, arg1: simple_func(arg0, *arg1)
@@ -39,7 +39,7 @@ x.__del__() # $ Alert[py/explicit-call-to-delete]
#Unhashable object
def func():
mapping = dict(); unhash = list()
return mapping[unhash] # $ Alert[py/hash-unhashable-value]
return mapping[unhash]
#Using 'is' when should be using '=='
s = "Hello " + "World"
@@ -86,9 +86,9 @@ class XIter(object):
def non_container():
seq = XIter()
if 1 in seq: # $ Alert[py/member-test-non-container]
if 1 in seq:
pass
if 1 not in seq: # $ Alert[py/member-test-non-container]
if 1 not in seq:
pass
#Container inheriting from builtin
@@ -138,15 +138,15 @@ class SubTest(Test):
#Some more lambdas
#Unnecessary lambdas
lambda arg0: len(arg0) # $ Alert[py/unnecessary-lambda]
lambda arg0: XIter.next(arg0) # $ Alert[py/unnecessary-lambda]
lambda arg0: len(arg0)
lambda arg0: XIter.next(arg0)
class UL(object):
def f(self, x):
pass
def g(self):
return lambda x: self.f(x) # $ Alert[py/unnecessary-lambda]
return lambda x: self.f(x)
# these lambdas are necessary
lambda arg0: XIter.next(arg0, arg1)

View File

@@ -2,16 +2,16 @@
def expected_mapping_for_fmt_string():
x = [ u'list', u'not', u'mapping' ]
print (u"%(name)s" % x) # $ Alert[py/percent-format/not-mapping]
print (u"%(name)s" % x)
def unsupported_format_char(arg):
print (u"%Z" % arg) # $ Alert[py/percent-format/unsupported-character]
def wrong_arg_count_format(arg):
print(u"%s %s" % (arg, arg, 0)) # $ Alert[py/percent-format/wrong-arguments]
print(u"%s %s" % (arg, arg, 0))
format = u"%hd"
args = (1, u'foo')
print(format % args) # $ Alert[py/percent-format/wrong-arguments]
print(format % args)
def ok():

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
class ExplicitReturnInInit(object):
def __init__(self):
return self # $ Alert[py/explicit-return-in-init]
return self
# These are OK
class ExplicitReturnNoneInInit(object):
@@ -99,4 +99,4 @@ class InitReturnsCallResult6(object):
p = procedure_implicit_none()
else:
p = not_ok
return p() # $ Alert[py/explicit-return-in-init]
return p()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -15,11 +15,11 @@ def ok2(x):
else:
return "Hi"
def cr1(x): # $ Alert[py/mixed-returns]
def cr1(x):
if x:
return 4
def cr2(x): # $ Alert[py/mixed-returns]
def cr2(x):
if x:
return 4
else:
@@ -74,7 +74,7 @@ def ok4(x):
def use_implicit_return_value(arg):
x = do_nothing() # $ Alert[py/procedure-return-value-used]
x = do_nothing()
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() # $ Alert[py/ignored-return-value]
ok4() # $ Alert[py/ignored-return-value]
sorted([1,2]) # $ Alert[py/ignored-return-value]
ok2()
ok4()
sorted([1,2])
d = {}
@@ -231,7 +231,7 @@ def mutli_return(arg):
if arg:
return do_something()
else:
return do_nothing() # $ Alert[py/procedure-return-value-used]
return do_nothing()
#Modification of parameter with default
@@ -333,7 +333,7 @@ def mismatched_multi_assign(x):
return a,b
def ok_match(x): # $ SPURIOUS: Alert[py/mixed-returns] # FP
def ok_match(x): # FP
match x:
case True | 'true':
return 0
@@ -341,7 +341,7 @@ def ok_match(x): # $ SPURIOUS: Alert[py/mixed-returns] # FP
raise ValueError(x)
def ok_match2(x): # $ SPURIOUS: Alert[py/mixed-returns] # FP
def ok_match2(x): # FP
match x:
case None:
return 0

View File

@@ -1,2 +1 @@
query: Imports/ModuleImportsItself.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Imports/ModuleImportsItself.ql

View File

@@ -5,7 +5,7 @@ import test_module2 # $ Alert[py/import-and-import-from]
from test_module2 import func
#Module imports itself
import imports_test # $ Alert[py/import-own-module]
import imports_test
import pkg_ok
import pkg_notok

View File

@@ -1,7 +1,7 @@
class Foo(object):
pass
import pkg_notok # $ Alert[py/import-and-import-from] Alert[py/import-own-module]
import pkg_notok # $ Alert[py/import-and-import-from]
# This import is a bit tricky. It will make `bar` available in as `pkg_notok.bar` as a
# side effect (see https://docs.python.org/3/reference/import.html#submodules), but the
@@ -9,6 +9,6 @@ import pkg_notok # $ Alert[py/import-and-import-from] Alert[py/import-own-module
# module imports itself.
import pkg_notok.bar
from pkg_notok import Foo # $ Alert[py/import-own-module]
from pkg_notok import Foo as NotOkFoo # $ Alert[py/import-own-module]
from pkg_notok import * # $ Alert[py/import-own-module]
from pkg_notok import Foo
from pkg_notok import Foo as NotOkFoo
from pkg_notok import *

View File

@@ -1,2 +1 @@
query: Imports/ModuleLevelCyclicImport.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Imports/ModuleLevelCyclicImport.ql

View File

@@ -5,4 +5,4 @@ import module4
@dataclasses.dataclass()
class Foo:
bars: typing.List[module4.Bar] # $ Alert
bars: typing.List[module4.Bar]

View File

@@ -5,5 +5,5 @@ import module3
@dataclasses.dataclass()
class Bar:
def is_in_foo(self, foo: module3.Foo): # $ Alert
def is_in_foo(self, foo: module3.Foo):
return self in foo.bars

View File

@@ -1,2 +1 @@
query: Imports/CyclicImport.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Imports/CyclicImport.ql

View File

@@ -1,2 +1 @@
query: Imports/ModuleLevelCyclicImport.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Imports/ModuleLevelCyclicImport.ql

View File

@@ -1,2 +1 @@
query: Imports/CyclicImport.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Imports/CyclicImport.ql

View File

@@ -1,2 +1 @@
query: Imports/ModuleLevelCyclicImport.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Imports/ModuleLevelCyclicImport.ql

View File

@@ -1,2 +1 @@
query: Imports/CyclicImport.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Imports/CyclicImport.ql

View File

@@ -1,2 +1 @@
query: Imports/ModuleLevelCyclicImport.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql
Imports/ModuleLevelCyclicImport.ql

View File

@@ -1,20 +1,20 @@
# potentially crashing cycles
import module2
import module3 # $ Alert[py/cyclic-import]
import module3
a1 = module2.a2 # $ Alert[py/unsafe-cyclic-import]
a1 = module2.a2
b1 = 2
# bad style cycles
import module4 # $ Alert[py/cyclic-import]
import module4
def foo():
import module5 # $ Alert[py/cyclic-import]
import module5
# okay, because some of the cycle is not top level
import module6 # $ Alert[py/cyclic-import]
import module6
# OK because this import occurs after relevant definition (a1)
import module8 # $ Alert[py/cyclic-import]
import module8
#OK because cycle is guarded by `if False:`
from module10 import x

View File

@@ -1,4 +1,4 @@
import module1
# direct use
a2 = module1.a1 # $ Alert[py/unsafe-cyclic-import]
a2 = module1.a1

Some files were not shown because too many files have changed in this diff Show More