Jikka-5.6.0.0: A transpiler from Python to C++ for competitive programming
Safe HaskellNone
LanguageHaskell2010

Jikka.RestrictedPython.Language.Lint

Synopsis

Documentation

hasSubscriptionInLoopCounters :: Program -> Bool Source #

hasSubscriptionInLoopCounters checks that there are SubscriptTrg in loop counters of for-loops. This includes loop counters of ListComp. For example, the followings has such subscriptions.

for a[0] in range(100):
    pass
return a[0]  # => 99
a = [0]
b = [0 for a[0] in range(100)]
return a[0]  # => 99

NOTE: This is allowd in the standard Python.

hasLeakOfLoopCounters :: Program -> Bool Source #

hasLeakOfLoopCounters checks that there are leaks of loop counters of for-loops. For example, the following has a leak.

for i in range(100):
    pass
return i  # => 100

hasAssignmentToLoopCounters :: Program -> Bool Source #

hasAssignmentToLoopCounters checks that there are assignments to loop counters of for-loops. For example, the following has the assignment.

for i in range(100):
    i += 1

hasAssignmentToLoopIterators :: Program -> Bool Source #

hasAssignmentToLoopIterators checks that there are assignments to loop iterators of for-loops. For example, the followings have the assignments.

a = list(range(10))
for i in a:
    a[5] = i
a = 0
for i in f(a):
    a += i

hasReturnInLoops :: Program -> Bool Source #

hasReturnInLoops checks that there are return-statements in for-loops. For example, the following has such a return-statement.

a = list(range(10))
for i in a:
    return True

hasMixedAssignment :: Program -> Bool Source #

hasMixedAssignment checks that there are assignments which assign to both of bare variables and subscripted variables. For example, the following is such an assignment.

a, b[0] = list(range(10))

NOTE: this doesn't check loop counters of For or ListComp.

hasNonTrivialSubscriptedAssignmentInForLoops :: Program -> Bool Source #

hasNonTrivialSubscriptedAssignmentInForLoops checks that there are assignments with non-trivial subscriptions in for-loops. A trivial subscription is a sequence of subscriptions to a variable with constant indices and at most one trivial loop-counter indices for each loops. A constant index is an expr which has a constant value in the loop. A trivial loop-counter index is the loop counter from "range(n)", "range(n, m)" or "enumerate(a)" with optional post-addition with a positive int literal.

For example, the followings have such assignments.

x = 0
for i in range(10):
    x += 1
    a[x] += 1
for i in range(10):
    j = i
    a[j] += 1
for i in range(10):
    a[2 * i] += 1
for i in range(10):
    a[1 + i] += 1
for i in range(10):
    a[i - 1] += 1
c = 1
for i in range(10):
    a[i + c] += 1
for i in range(10):
    a[i][i] += 1
for i in [1, 2, 3]:
    a[i] += 1
b = range(10)
for i in b:
    a[i] += 1
for i in range(0, 10, 2):
    a[i] += 1
for i, b_i in enumerate(b):
    a[b_i] += i

For example, the followings don't have such assignments.

c = 0
for i in range(10):
    a[c] += 1
for i in range(10):
    a[i] += 1
for i in range(10):
    a[i + 1] += 1
for i in range(10):
    for j in range(10):
        a[i + 1][j] += 1
for i in range(1, 10):
    a[i] += 1
for i, b_i in enumerate(b):
    a[i] += b_i

hasAssignmentToBuiltin :: Program -> Bool Source #

hasAssginmentToBuiltin checks that there are assignments to builtin functions. For example, the followings have such assignments.

map = 3
return [range for range in range(10)]

hasNonResolvedBuiltin :: Program -> Bool Source #

hasNonResolvedBuiltin checks that there are not resolved builtin functions. This always doesn't hold after ResolveBuiltin.