The following issues were found
tests/basics/async_with_return.py
12 issues
Line: 1
Column: 1
# test async with, escaped by a return
class AContext:
async def __aenter__(self):
print('enter')
return 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
Reported by Pylint.
Line: 3
Column: 1
# test async with, escaped by a return
class AContext:
async def __aenter__(self):
print('enter')
return 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
Reported by Pylint.
Line: 7
Column: 5
async def __aenter__(self):
print('enter')
return 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
async def f1():
async with AContext():
print('body')
Reported by Pylint.
Line: 10
Column: 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
async def f1():
async with AContext():
print('body')
return
o = f1()
Reported by Pylint.
Line: 10
Column: 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
async def f1():
async with AContext():
print('body')
return
o = f1()
Reported by Pylint.
Line: 15
Column: 1
print('body')
return
o = f1()
try:
o.send(None)
except StopIteration:
print('finished')
Reported by Pylint.
Line: 21
Column: 1
except StopIteration:
print('finished')
async def f2():
try:
async with AContext():
print('body')
return
finally:
Reported by Pylint.
Line: 21
Column: 1
except StopIteration:
print('finished')
async def f2():
try:
async with AContext():
print('body')
return
finally:
Reported by Pylint.
Line: 29
Column: 1
finally:
print('finally')
o = f2()
try:
o.send(None)
except StopIteration:
print('finished')
Reported by Pylint.
Line: 35
Column: 1
except StopIteration:
print('finished')
async def f3():
try:
try:
async with AContext():
print('body')
return
Reported by Pylint.
tests/basics/async_with_break.py
12 issues
Line: 15
Column: 13
async with AContext():
print('body')
break
print('no 1')
print('no 2')
o = f1()
try:
print(o.send(None))
Reported by Pylint.
Line: 30
Column: 17
async with AContext():
print('body')
break
print('no 1')
finally:
print('finally')
print('no 2')
o = f2()
Reported by Pylint.
Line: 48
Column: 21
async with AContext():
print('body')
break
print('no 1')
finally:
print('finally inner')
finally:
print('finally outer')
print('no 2')
Reported by Pylint.
Line: 1
Column: 1
# test async with, escaped by a break
class AContext:
async def __aenter__(self):
print('enter')
return 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
Reported by Pylint.
Line: 3
Column: 1
# test async with, escaped by a break
class AContext:
async def __aenter__(self):
print('enter')
return 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
Reported by Pylint.
Line: 7
Column: 5
async def __aenter__(self):
print('enter')
return 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
async def f1():
while 1:
async with AContext():
Reported by Pylint.
Line: 10
Column: 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
async def f1():
while 1:
async with AContext():
print('body')
break
print('no 1')
Reported by Pylint.
Line: 10
Column: 1
async def __aexit__(self, exc_type, exc, tb):
print('exit', exc_type, exc)
async def f1():
while 1:
async with AContext():
print('body')
break
print('no 1')
Reported by Pylint.
Line: 24
Column: 1
except StopIteration:
print('finished')
async def f2():
while 1:
try:
async with AContext():
print('body')
break
Reported by Pylint.
Line: 24
Column: 1
except StopIteration:
print('finished')
async def f2():
while 1:
try:
async with AContext():
print('body')
break
Reported by Pylint.
tests/inlineasm/asmconst.py
12 issues
Line: 4
Column: 2
# test constants in assembler
@micropython.asm_thumb
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
Reported by Pylint.
Line: 6
Column: 11
@micropython.asm_thumb
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
print(hex(c1()))
Reported by Pylint.
Line: 6
Column: 5
@micropython.asm_thumb
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
print(hex(c1()))
Reported by Pylint.
Line: 7
Column: 11
@micropython.asm_thumb
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
print(hex(c1()))
Reported by Pylint.
Line: 7
Column: 5
@micropython.asm_thumb
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
print(hex(c1()))
Reported by Pylint.
Line: 8
Column: 17
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
print(hex(c1()))
Reported by Pylint.
Line: 8
Column: 5
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
print(hex(c1()))
Reported by Pylint.
Line: 8
Column: 9
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
print(hex(c1()))
Reported by Pylint.
Line: 8
Column: 13
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
print(hex(c1()))
Reported by Pylint.
Line: 1
Column: 1
# test constants in assembler
@micropython.asm_thumb
def c1():
movwt(r0, 0xFFFFFFFF)
movwt(r1, 0xF0000000)
sub(r0, r0, r1)
Reported by Pylint.
tests/multi_net/tcp_accept_recv.py
12 issues
Line: 10
Column: 5
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
s.listen(1)
multitest.next()
Reported by Pylint.
Line: 10
Column: 26
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
s.listen(1)
multitest.next()
Reported by Pylint.
Line: 15
Column: 5
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
s.listen(1)
multitest.next()
s.accept()
try:
print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN
except OSError as er:
print(er.errno)
Reported by Pylint.
Line: 26
Column: 5
# Client
def instance1():
multitest.next()
s = socket.socket()
s.connect(socket.getaddrinfo(IP, PORT)[0][-1])
s.send(b"GET / HTTP/1.0\r\n\r\n")
s.close()
Reported by Pylint.
Line: 28
Column: 34
def instance1():
multitest.next()
s = socket.socket()
s.connect(socket.getaddrinfo(IP, PORT)[0][-1])
s.send(b"GET / HTTP/1.0\r\n\r\n")
s.close()
Reported by Pylint.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
s.listen(1)
multitest.next()
s.accept()
try:
print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN
Reported by Bandit.
Line: 1
Column: 1
# Test recv on socket that just accepted a connection
import socket
PORT = 8000
# Server
def instance0():
Reported by Pylint.
Line: 9
Column: 1
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
s.listen(1)
Reported by Pylint.
Line: 11
Column: 5
# Server
def instance0():
multitest.globals(IP=multitest.get_network_ip())
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(socket.getaddrinfo("0.0.0.0", PORT)[0][-1])
s.listen(1)
multitest.next()
s.accept()
Reported by Pylint.
Line: 19
Column: 5
s.accept()
try:
print("recv", s.recv(10)) # should raise Errno 107 ENOTCONN
except OSError as er:
print(er.errno)
s.close()
# Client
Reported by Pylint.
ports/esp32/makeimg.py
12 issues
Line: 7
Column: 1
sys.path.append(os.getenv("IDF_PATH") + "/components/partition_table")
import gen_esp32part
OFFSET_BOOTLOADER_DEFAULT = 0x1000
OFFSET_PARTITIONS_DEFAULT = 0x8000
Reported by Pylint.
Line: 1
Column: 1
# Combine bootloader, partition table and application into a final binary.
import os, sys
sys.path.append(os.getenv("IDF_PATH") + "/components/partition_table")
import gen_esp32part
OFFSET_BOOTLOADER_DEFAULT = 0x1000
Reported by Pylint.
Line: 3
Column: 1
# Combine bootloader, partition table and application into a final binary.
import os, sys
sys.path.append(os.getenv("IDF_PATH") + "/components/partition_table")
import gen_esp32part
OFFSET_BOOTLOADER_DEFAULT = 0x1000
Reported by Pylint.
Line: 7
Column: 1
sys.path.append(os.getenv("IDF_PATH") + "/components/partition_table")
import gen_esp32part
OFFSET_BOOTLOADER_DEFAULT = 0x1000
OFFSET_PARTITIONS_DEFAULT = 0x8000
Reported by Pylint.
Line: 13
Column: 1
OFFSET_PARTITIONS_DEFAULT = 0x8000
def load_sdkconfig_hex_value(filename, value, default):
value = "CONFIG_" + value + "="
with open(filename, "r") as f:
for line in f:
if line.startswith(value):
return int(line.split("=", 1)[1], 16)
Reported by Pylint.
Line: 15
Column: 33
def load_sdkconfig_hex_value(filename, value, default):
value = "CONFIG_" + value + "="
with open(filename, "r") as f:
for line in f:
if line.startswith(value):
return int(line.split("=", 1)[1], 16)
return default
Reported by Pylint.
Line: 22
Column: 1
return default
def load_partition_table(filename):
with open(filename, "rb") as f:
return gen_esp32part.PartitionTable.from_binary(f.read())
# Extract command-line arguments.
Reported by Pylint.
Line: 23
Column: 34
def load_partition_table(filename):
with open(filename, "rb") as f:
return gen_esp32part.PartitionTable.from_binary(f.read())
# Extract command-line arguments.
arg_sdkconfig = sys.argv[1]
Reported by Pylint.
Line: 46
Column: 1
partition_table = load_partition_table(arg_partitions_bin)
max_size_bootloader = offset_partitions - offset_bootloader
max_size_partitions = 0
offset_application = 0
max_size_application = 0
# Inspect the partition table to find offsets and maximum sizes.
for part in partition_table:
Reported by Pylint.
Line: 47
Column: 1
max_size_bootloader = offset_partitions - offset_bootloader
max_size_partitions = 0
offset_application = 0
max_size_application = 0
# Inspect the partition table to find offsets and maximum sizes.
for part in partition_table:
if part.name == "nvs":
Reported by Pylint.
examples/network/http_server_ssl.py
12 issues
Line: 1
Column: 1
import ubinascii as binascii
try:
import usocket as socket
except:
import socket
import ussl as ssl
Reported by Pylint.
Line: 7
Column: 1
import usocket as socket
except:
import socket
import ussl as ssl
# This self-signed key/cert pair is randomly generated and to be used for
# testing/demonstration only. You should always generate your own key/cert.
key = binascii.unhexlify(
Reported by Pylint.
Line: 5
Column: 1
try:
import usocket as socket
except:
import socket
import ussl as ssl
# This self-signed key/cert pair is randomly generated and to be used for
Reported by Pylint.
Line: 52
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html
s = socket.socket()
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8443)
print("Bind address info:", ai)
addr = ai[0][-1]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
Reported by Bandit.
Line: 89
Column: 20
print(h)
if req:
client_s.write(CONTENT % counter)
except Exception as e:
print("Exception serving request:", e)
else:
print(client_s.recv(4096))
client_s.send(CONTENT % counter)
client_s.close()
Reported by Pylint.
Line: 1
Column: 1
import ubinascii as binascii
try:
import usocket as socket
except:
import socket
import ussl as ssl
Reported by Pylint.
Line: 48
Column: 1
"""
def main(use_stream=True):
s = socket.socket()
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8443)
print("Bind address info:", ai)
Reported by Pylint.
Line: 49
Column: 5
def main(use_stream=True):
s = socket.socket()
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8443)
print("Bind address info:", ai)
addr = ai[0][-1]
Reported by Pylint.
Line: 52
Column: 5
s = socket.socket()
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8443)
print("Bind address info:", ai)
addr = ai[0][-1]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
Reported by Pylint.
Line: 83
Column: 21
req = client_s.readline()
print(req)
while True:
h = client_s.readline()
if h == b"" or h == b"\r\n":
break
print(h)
if req:
client_s.write(CONTENT % counter)
Reported by Pylint.
tests/perf_bench/benchrun.py
12 issues
Line: 13
Column: 18
# Pick sensible parameters given N, M
cur_nm = (0, 0)
param = None
for nm, p in bm_params.items():
if 10 * nm[0] <= 12 * N and nm[1] <= M and nm > cur_nm:
cur_nm = nm
param = p
if param is None:
print(-1, -1, "no matching params")
Reported by Pylint.
Line: 22
Column: 19
return
# Run and time benchmark
run, result = bm_setup(param)
t0 = ticks_us()
run()
t1 = ticks_us()
norm, out = result()
print(ticks_diff(t1, t0), norm, out)
Reported by Pylint.
Line: 1
Column: 1
def bm_run(N, M):
try:
from utime import ticks_us, ticks_diff
except ImportError:
import time
ticks_us = lambda: int(time.perf_counter() * 1000000)
ticks_diff = lambda a, b: a - b
Reported by Pylint.
Line: 1
Column: 1
def bm_run(N, M):
try:
from utime import ticks_us, ticks_diff
except ImportError:
import time
ticks_us = lambda: int(time.perf_counter() * 1000000)
ticks_diff = lambda a, b: a - b
Reported by Pylint.
Line: 1
Column: 1
def bm_run(N, M):
try:
from utime import ticks_us, ticks_diff
except ImportError:
import time
ticks_us = lambda: int(time.perf_counter() * 1000000)
ticks_diff = lambda a, b: a - b
Reported by Pylint.
Line: 1
Column: 1
def bm_run(N, M):
try:
from utime import ticks_us, ticks_diff
except ImportError:
import time
ticks_us = lambda: int(time.perf_counter() * 1000000)
ticks_diff = lambda a, b: a - b
Reported by Pylint.
Line: 3
Column: 9
def bm_run(N, M):
try:
from utime import ticks_us, ticks_diff
except ImportError:
import time
ticks_us = lambda: int(time.perf_counter() * 1000000)
ticks_diff = lambda a, b: a - b
Reported by Pylint.
Line: 5
Column: 9
try:
from utime import ticks_us, ticks_diff
except ImportError:
import time
ticks_us = lambda: int(time.perf_counter() * 1000000)
ticks_diff = lambda a, b: a - b
# Pick sensible parameters given N, M
Reported by Pylint.
Line: 13
Column: 9
# Pick sensible parameters given N, M
cur_nm = (0, 0)
param = None
for nm, p in bm_params.items():
if 10 * nm[0] <= 12 * N and nm[1] <= M and nm > cur_nm:
cur_nm = nm
param = p
if param is None:
print(-1, -1, "no matching params")
Reported by Pylint.
Line: 13
Column: 13
# Pick sensible parameters given N, M
cur_nm = (0, 0)
param = None
for nm, p in bm_params.items():
if 10 * nm[0] <= 12 * N and nm[1] <= M and nm > cur_nm:
cur_nm = nm
param = p
if param is None:
print(-1, -1, "no matching params")
Reported by Pylint.
tests/basics/getattr.py
12 issues
Line: 14
Column: 1
print(a.a, a.b)
# test that any exception raised in __getattr__ propagates out
class A:
def __getattr__(self, attr):
if attr == "value":
raise ValueError(123)
else:
raise AttributeError(456)
Reported by Pylint.
Line: 1
Column: 1
# test __getattr__
class A:
def __init__(self, d):
self.d = d
def __getattr__(self, attr):
return self.d[attr]
Reported by Pylint.
Line: 3
Column: 1
# test __getattr__
class A:
def __init__(self, d):
self.d = d
def __getattr__(self, attr):
return self.d[attr]
Reported by Pylint.
Line: 3
Column: 1
# test __getattr__
class A:
def __init__(self, d):
self.d = d
def __getattr__(self, attr):
return self.d[attr]
Reported by Pylint.
Line: 3
Column: 1
# test __getattr__
class A:
def __init__(self, d):
self.d = d
def __getattr__(self, attr):
return self.d[attr]
Reported by Pylint.
Line: 5
Column: 9
class A:
def __init__(self, d):
self.d = d
def __getattr__(self, attr):
return self.d[attr]
a = A({'a':1, 'b':2})
Reported by Pylint.
Line: 14
Column: 1
print(a.a, a.b)
# test that any exception raised in __getattr__ propagates out
class A:
def __getattr__(self, attr):
if attr == "value":
raise ValueError(123)
else:
raise AttributeError(456)
Reported by Pylint.
Line: 14
Column: 1
print(a.a, a.b)
# test that any exception raised in __getattr__ propagates out
class A:
def __getattr__(self, attr):
if attr == "value":
raise ValueError(123)
else:
raise AttributeError(456)
Reported by Pylint.
Line: 14
Column: 1
print(a.a, a.b)
# test that any exception raised in __getattr__ propagates out
class A:
def __getattr__(self, attr):
if attr == "value":
raise ValueError(123)
else:
raise AttributeError(456)
Reported by Pylint.
Line: 16
Column: 9
# test that any exception raised in __getattr__ propagates out
class A:
def __getattr__(self, attr):
if attr == "value":
raise ValueError(123)
else:
raise AttributeError(456)
a = A()
try:
Reported by Pylint.
lib/littlefs/lfs2_util.h
12 issues
Line: 171
CWE codes:
758
return __builtin_bswap32(a);
#else
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
Reported by Cppcheck.
Line: 171
CWE codes:
758
return __builtin_bswap32(a);
#else
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
Reported by Cppcheck.
Line: 172
CWE codes:
758
#else
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
static inline uint32_t lfs2_tole32(uint32_t a) {
Reported by Cppcheck.
Line: 172
CWE codes:
758
#else
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
static inline uint32_t lfs2_tole32(uint32_t a) {
Reported by Cppcheck.
Line: 173
CWE codes:
758
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
static inline uint32_t lfs2_tole32(uint32_t a) {
return lfs2_fromle32(a);
Reported by Cppcheck.
Line: 173
CWE codes:
758
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
static inline uint32_t lfs2_tole32(uint32_t a) {
return lfs2_fromle32(a);
Reported by Cppcheck.
Line: 195
CWE codes:
758
return a;
#else
return (((uint8_t*)&a)[0] << 24) |
(((uint8_t*)&a)[1] << 16) |
(((uint8_t*)&a)[2] << 8) |
(((uint8_t*)&a)[3] << 0);
#endif
}
Reported by Cppcheck.
Line: 195
CWE codes:
758
return a;
#else
return (((uint8_t*)&a)[0] << 24) |
(((uint8_t*)&a)[1] << 16) |
(((uint8_t*)&a)[2] << 8) |
(((uint8_t*)&a)[3] << 0);
#endif
}
Reported by Cppcheck.
Line: 196
CWE codes:
758
#else
return (((uint8_t*)&a)[0] << 24) |
(((uint8_t*)&a)[1] << 16) |
(((uint8_t*)&a)[2] << 8) |
(((uint8_t*)&a)[3] << 0);
#endif
}
static inline uint32_t lfs2_tobe32(uint32_t a) {
Reported by Cppcheck.
Line: 196
CWE codes:
758
#else
return (((uint8_t*)&a)[0] << 24) |
(((uint8_t*)&a)[1] << 16) |
(((uint8_t*)&a)[2] << 8) |
(((uint8_t*)&a)[3] << 0);
#endif
}
static inline uint32_t lfs2_tobe32(uint32_t a) {
Reported by Cppcheck.
tests/extmod/urandom_extra.py
12 issues
Line: 8
Column: 9
import random
except ImportError:
print("SKIP")
raise SystemExit
try:
random.randint
except AttributeError:
print("SKIP")
Reported by Pylint.
Line: 14
Column: 5
random.randint
except AttributeError:
print("SKIP")
raise SystemExit
print("randrange")
for i in range(50):
assert 0 <= random.randrange(4) < 4
assert 2 <= random.randrange(2, 6) < 6
Reported by Pylint.
Line: 1
Column: 1
try:
import urandom as random
except ImportError:
try:
import random
except ImportError:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
print("randrange")
for i in range(50):
assert 0 <= random.randrange(4) < 4
assert 2 <= random.randrange(2, 6) < 6
assert -2 <= random.randrange(-2, 2) < 2
assert random.randrange(1, 9, 2) in (1, 3, 5, 7)
assert random.randrange(2, 1, -1) in (1, 2)
Reported by Bandit.
Line: 19
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
print("randrange")
for i in range(50):
assert 0 <= random.randrange(4) < 4
assert 2 <= random.randrange(2, 6) < 6
assert -2 <= random.randrange(-2, 2) < 2
assert random.randrange(1, 9, 2) in (1, 3, 5, 7)
assert random.randrange(2, 1, -1) in (1, 2)
# empty range
Reported by Bandit.
Line: 20
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
for i in range(50):
assert 0 <= random.randrange(4) < 4
assert 2 <= random.randrange(2, 6) < 6
assert -2 <= random.randrange(-2, 2) < 2
assert random.randrange(1, 9, 2) in (1, 3, 5, 7)
assert random.randrange(2, 1, -1) in (1, 2)
# empty range
try:
Reported by Bandit.
Line: 21
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert 0 <= random.randrange(4) < 4
assert 2 <= random.randrange(2, 6) < 6
assert -2 <= random.randrange(-2, 2) < 2
assert random.randrange(1, 9, 2) in (1, 3, 5, 7)
assert random.randrange(2, 1, -1) in (1, 2)
# empty range
try:
random.randrange(0)
Reported by Bandit.
Line: 22
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert 2 <= random.randrange(2, 6) < 6
assert -2 <= random.randrange(-2, 2) < 2
assert random.randrange(1, 9, 2) in (1, 3, 5, 7)
assert random.randrange(2, 1, -1) in (1, 2)
# empty range
try:
random.randrange(0)
except ValueError:
Reported by Bandit.
Line: 50
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
print("randint")
for i in range(50):
assert 0 <= random.randint(0, 4) <= 4
assert 2 <= random.randint(2, 6) <= 6
assert -2 <= random.randint(-2, 2) <= 2
# empty range
try:
Reported by Bandit.
Line: 51
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
print("randint")
for i in range(50):
assert 0 <= random.randint(0, 4) <= 4
assert 2 <= random.randint(2, 6) <= 6
assert -2 <= random.randint(-2, 2) <= 2
# empty range
try:
random.randint(2, 1)
Reported by Bandit.