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/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

View File

@@ -1,2 +1,2 @@
# use via import member
from module1 import a1 # $ Alert[py/unsafe-cyclic-import]
from module1 import a1

View File

@@ -1 +1 @@
import module1 # $ Alert[py/cyclic-import]
import module1

View File

@@ -1 +1 @@
import module1 # $ Alert[py/cyclic-import]
import module1

View File

@@ -1,2 +1,2 @@
def foo():
import module7 # $ Alert[py/cyclic-import]
import module7

View File

@@ -1 +1 @@
from module1 import a1 # $ Alert[py/cyclic-import]
from module1 import a1

View File

@@ -1,4 +1,4 @@
import module1 # $ Alert[py/cyclic-import]
import module1
class Foo(object):
a = module1.a1

View File

@@ -1,6 +1,6 @@
x = 1
import main # $ Alert[py/cyclic-import]
import main
y = 2

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
from mutable_attr import x, y # $ Alert[py/import-of-mutable-attribute]
from mutable_attr import x, y
def f():
print(x)

View File

@@ -19,7 +19,7 @@ for module in range(10): # $ Alert[py/import-shadowed-loop-variable]
#Import * used
from module import * # $ Alert[py/import-star-used]
from module_without_all import * # $ Alert[py/import-star-used] Alert[py/polluting-import]
from module_without_all import * # $ Alert[py/import-star-used]
#Unused import

View File

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

View File

@@ -2,7 +2,7 @@
# lines
from typing import Optional
from unknown import foo, bar # $ Alert
from unknown import foo, bar
var: Optional['foo'] = None

View File

@@ -3,6 +3,6 @@
from typing import Optional
from unknown import foo
from unknown import bar # $ Alert
from unknown import bar
var: Optional['foo'] = None

View File

@@ -1,13 +1,13 @@
#Multiple imports on a single line
import module1, module2 # $ Alert
import module1, module2
#Cyclic import
import cycle # $ Alert
import cycle
#Top level cyclic import
import top_level_cycle # $ Alert
import top_level_cycle
#Import shadowed by loop variable
@@ -24,14 +24,14 @@ from module_without_all import *
#Unused import
from module2 import func1
from module2 import func2 # $ Alert
from module2 import func2
module1.func
func1
#Duplicate import
import module1
import module2 # $ Alert
import module2
#OK -- Import used in epytext documentation.
import used_in_docs
@@ -113,6 +113,6 @@ def baz() -> Optional['subexpression_return_type']:
pass
from pytest_fixtures import not_a_fixture # $ Alert # BAD
from pytest_fixtures import not_a_fixture # BAD
from pytest_fixtures import fixture, wrapped_fixture # GOOD (pytest fixtures are used implicitly by pytest)
from pytest_fixtures import session_fixture, wrapped_autouse_fixture # GOOD (pytest fixtures are used implicitly by pytest)

View File

@@ -1 +1 @@
query: Metrics/CyclomaticComplexity.ql
Metrics/CyclomaticComplexity.ql

View File

@@ -1 +1 @@
query: Metrics/DirectImports.ql
Metrics/DirectImports.ql

View File

@@ -1 +1 @@
query: Metrics/TransitiveImports.ql
Metrics/TransitiveImports.ql

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,10 +3,10 @@
def y(seq):
y_accum = ''
for s in seq:
y_accum += s # $ Alert[py/string-concatenation-in-loop]
y_accum += s
def z(seq):
z_accum = ''
for s in seq:
z_accum = z_accum + s # $ Alert[py/string-concatenation-in-loop]
z_accum = z_accum + s

View File

@@ -16,7 +16,7 @@ def not_cc():
#Mismatch in multiple assignment
def mima():
x, y, z = 1, 2 # $ Alert[py/mismatched-multiple-assignment]
x, y, z = 1, 2
return x, y, z
#Statement has no effect (4 statements, 3 of which are violations)
@@ -51,10 +51,10 @@ ok = ok # Pyflakes
class Redundant(object):
x = x # OK
x = x # $ Alert[py/redundant-assignment] # violation
x = x # violation
def __init__(self, args):
args = args # $ Alert[py/redundant-assignment] # violation
args = args # violation
if sys.version_info < (3,):
bytes = str
@@ -116,7 +116,7 @@ def maybe_property(x):
class WithoutProp(object):
def meth(self):
self.x = self.x # $ Alert[py/redundant-assignment]
self.x = self.x
#Accessing a property has an effect:
def prop_acc():
@@ -166,7 +166,7 @@ if False:
def error_mismatched_multi_assign_list():
a,b,c = [1,2,3,4,5] # $ Alert[py/mismatched-multiple-assignment]
a,b,c = [1,2,3,4,5]
def returning_different_tuple_sizes(x):
if x:
@@ -175,7 +175,7 @@ def returning_different_tuple_sizes(x):
return 1,2,3,4,5,6
def error_indirect_mismatched_multi_assign(x):
a, b, c = returning_different_tuple_sizes(x) # $ Alert[py/mismatched-multiple-assignment]
a, b, c = returning_different_tuple_sizes(x)
return a, b, c

View File

@@ -47,7 +47,7 @@ class NonIterator(object):
def __init__(self):
pass
for x in NonIterator(): # $ Alert[py/non-iterable-in-for-loop]
for x in NonIterator():
do_something(x)
#None in for loop

View File

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

View File

@@ -6,6 +6,6 @@ class T(unittest.TestCase):
l = 10
s = [0]
with self.assertRaises(TypeError):
l[1000] # $ Alert[py/ineffectual-statement]
l[1000]
with self.assertRaises(IndexError):
s[1] # $ Alert[py/ineffectual-statement]
s[1]

View File

@@ -21,9 +21,9 @@ import sys
#Statement has no effect (4 statements, 3 of which are violations)
"Not a docstring" # This is acceptable as strings can be used as comments.
len # $ Alert[py/ineffectual-statement]
sys.argv + [] # $ Alert[py/ineffectual-statement]
3 == 4 # $ Alert[py/ineffectual-statement]
len
sys.argv + []
3 == 4
#The 'sys' statements have an effect
try:
@@ -77,7 +77,7 @@ x.deco
x.deco + 2
#No effect
x.func # $ Alert[py/ineffectual-statement]
x.func
#Cannot infer what attribute is, so be conservative
x.thing
@@ -113,7 +113,7 @@ def possible_fps(x):
h = Horrible()
h + "innocent bystander"
h < "upstanding citizen"
x - 3 # $ Alert[py/ineffectual-statement] #True positive
x - 3 #True positive
# Forgotten raise.

View File

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

View File

@@ -11,7 +11,7 @@ def sh1(x):
#Shadow Global
def sh2(x):
sh1 = x + 1 # $ Alert[py/local-shadows-global] #Shadows
sh1 = x + 1 #Shadows
sh1 = x + 0 # no shadowing warning for 2nd def
return sh1

View File

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

View File

@@ -19,12 +19,12 @@ def f(parameter):
helper # Explicitly as import
a # Imlicitly from ud_helper
defined
ug2 # $ Alert[py/undefined-global-variable] # ERROR
e # $ Alert[py/undefined-global-variable] # ERROR Defined in ud_helper, but not in __all__
ug2 # ERROR
e # ERROR Defined in ud_helper, but not in __all__
int
float
__file__ #OK all files have __file__ defined
__path__ # $ Alert[py/undefined-global-variable] #ERROR only modules have __path__ defined
__path__ #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 # $ Alert[py/undefined-global-variable]
ug3
ug3
ug3
ug3

View File

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

View File

@@ -2,7 +2,7 @@
class C:
def m1(self):
y = ug1 # $ Alert[py/undefined-global-variable]
y = ug1
x = 1
return y
@@ -10,16 +10,16 @@ class C:
return p
def m3(self, x1):
return u2 # $ Alert[py/uninitialized-local-variable]
return u2
u2 = x1
def m4(self, x2):
if x2:
u3 = 1
return u3 # $ Alert[py/uninitialized-local-variable]
return u3
def f():
y = ug1 # $ Alert[py/undefined-global-variable]
y = ug1
x = 1
return y
@@ -34,7 +34,7 @@ def q(x4):
def j(u4):
del u4
return u4 # $ Alert[py/uninitialized-local-variable]
return u4
def k(x5):
x5 + 1
@@ -43,7 +43,7 @@ def k(x5):
def m(x6):
if x6:
u6 = 1
u6 # $ Alert[py/uninitialized-local-variable]
u6
#The following are not uninitialized, but unreachable.
u6
u6
@@ -66,13 +66,13 @@ def check_del(cond):
del u8
else:
pass
u8 # $ Alert[py/uninitialized-local-variable]
u8
if cond:
u9 = 1
del u9
else:
u9 = 2
u9 # $ Alert[py/uninitialized-local-variable]
u9
if cond:
x10 = 1
del x10
@@ -82,10 +82,10 @@ def check_del(cond):
x10
u11 = 1
del u11
u11 # $ Alert[py/uninitialized-local-variable]
u11
u12 = "hi"
del u12
del u12 # $ Alert[py/uninitialized-local-variable]
del u12
#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 # $ Alert[py/uninitialized-local-variable]
return u14
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 # $ Alert[py/uninitialized-local-variable]
return u19
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) # $ Alert[py/uninitialized-local-variable]
j(x)
x = []
for p in seq:
x = p
@@ -173,9 +173,9 @@ def f(cond1, cond2):
else:
y = 1
if cond2:
return x # $ Alert[py/uninitialized-local-variable]
return x
else:
return y # $ Alert[py/uninitialized-local-variable]
return y
def needs_splitting(var):
if var:

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
__all__ = ["foo", "bar", "baz", "quux", "blat", "frob", "nosuch", "i_got_it_elsewhere"] # $ Alert[py/undefined-export]
__all__ = ["foo", "bar", "baz", "quux", "blat", "frob", "nosuch", "i_got_it_elsewhere"]
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: # $ Alert[py/uninitialized-local-variable]
if var == 1:
var = var + 1
elif var == 2:
var +- 3

View File

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

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