The following issues were found
tests/basics/try_finally_break.py
30 issues
Line: 18
Column: 1
f()
# where the finally swallows an exception
def f():
lst = [1, 2, 3]
for x in lst:
print('a', x)
try:
raise Exception
Reported by Pylint.
Line: 31
Column: 1
f()
# basic nested finally with break in inner finally
def f():
for i in range(2):
print('iter', i)
try:
raise TypeError
finally:
Reported by Pylint.
Line: 45
Column: 1
print(f())
# similar to above but more nesting
def f():
for i in range(2):
try:
raise ValueError
finally:
print(1)
Reported by Pylint.
Line: 62
Column: 1
print(f())
# lots of nesting
def f():
for i in range(2):
try:
raise ValueError
finally:
print(1)
Reported by Pylint.
Line: 79
Column: 1
print(f())
# basic case combined with try-else
def f(arg):
for _ in range(2):
print(1)
try:
if arg == 1:
raise ValueError
Reported by Pylint.
Line: 11
Column: 13
pass
finally:
print(2)
break
print(3)
print(4)
print(5)
f()
Reported by Pylint.
Line: 12
Column: 13
finally:
print(2)
break
print(3)
print(4)
print(5)
f()
# where the finally swallows an exception
Reported by Pylint.
Line: 26
Column: 13
raise Exception
finally:
print(1)
break
print('b', x)
f()
# basic nested finally with break in inner finally
def f():
Reported by Pylint.
Line: 41
Column: 17
try:
raise ValueError
finally:
break
print(f())
# similar to above but more nesting
def f():
for i in range(2):
Reported by Pylint.
Line: 46
Column: 9
# similar to above but more nesting
def f():
for i in range(2):
try:
raise ValueError
finally:
print(1)
try:
Reported by Pylint.
tests/inlineasm/asmargs.py
30 issues
Line: 4
Column: 2
# test passing arguments
@micropython.asm_thumb
def arg0():
mov(r0, 1)
print(arg0())
Reported by Pylint.
Line: 6
Column: 9
@micropython.asm_thumb
def arg0():
mov(r0, 1)
print(arg0())
Reported by Pylint.
Line: 6
Column: 5
@micropython.asm_thumb
def arg0():
mov(r0, 1)
print(arg0())
Reported by Pylint.
Line: 12
Column: 2
print(arg0())
@micropython.asm_thumb
def arg1(r0):
add(r0, r0, 1)
print(arg1(1))
Reported by Pylint.
Line: 14
Column: 5
@micropython.asm_thumb
def arg1(r0):
add(r0, r0, 1)
print(arg1(1))
Reported by Pylint.
Line: 20
Column: 2
print(arg1(1))
@micropython.asm_thumb
def arg2(r0, r1):
add(r0, r0, r1)
print(arg2(1, 2))
Reported by Pylint.
Line: 22
Column: 5
@micropython.asm_thumb
def arg2(r0, r1):
add(r0, r0, r1)
print(arg2(1, 2))
Reported by Pylint.
Line: 28
Column: 2
print(arg2(1, 2))
@micropython.asm_thumb
def arg3(r0, r1, r2):
add(r0, r0, r1)
add(r0, r0, r2)
Reported by Pylint.
Line: 30
Column: 5
@micropython.asm_thumb
def arg3(r0, r1, r2):
add(r0, r0, r1)
add(r0, r0, r2)
print(arg3(1, 2, 3))
Reported by Pylint.
Line: 31
Column: 5
@micropython.asm_thumb
def arg3(r0, r1, r2):
add(r0, r0, r1)
add(r0, r0, r2)
print(arg3(1, 2, 3))
Reported by Pylint.
tests/basics/builtin_override.py
30 issues
Line: 31
Column: 1
return M
builtins.__import__ = custom_import
__import__('A', None, None, None, 0)
import a
import a.b
from a import a
from a.b import a, b
from .a import a
from ..a import a, b
Reported by Pylint.
Line: 32
Column: 1
builtins.__import__ = custom_import
__import__('A', None, None, None, 0)
import a
import a.b
from a import a
from a.b import a, b
from .a import a
from ..a import a, b
Reported by Pylint.
Line: 33
Column: 1
__import__('A', None, None, None, 0)
import a
import a.b
from a import a
from a.b import a, b
from .a import a
from ..a import a, b
Reported by Pylint.
Line: 34
Column: 1
import a
import a.b
from a import a
from a.b import a, b
from .a import a
from ..a import a, b
Reported by Pylint.
Line: 35
Column: 1
import a.b
from a import a
from a.b import a, b
from .a import a
from ..a import a, b
Reported by Pylint.
Line: 36
Column: 1
from a import a
from a.b import a, b
from .a import a
from ..a import a, b
Reported by Pylint.
Line: 10
Column: 5
builtins.abs = lambda x: x + 1
except AttributeError:
print("SKIP")
raise SystemExit
print(abs(1))
# __build_class__ is handled in a special way
orig_build_class = __build_class__
Reported by Pylint.
Line: 23
Column: 34
builtins.__build_class__ = orig_build_class
# __import__ is handled in a special way
def custom_import(name, globals, locals, fromlist, level):
print('import', name, fromlist, level)
class M:
a = 1
b = 2
return M
Reported by Pylint.
Line: 23
Column: 25
builtins.__build_class__ = orig_build_class
# __import__ is handled in a special way
def custom_import(name, globals, locals, fromlist, level):
print('import', name, fromlist, level)
class M:
a = 1
b = 2
return M
Reported by Pylint.
Line: 23
Column: 34
builtins.__build_class__ = orig_build_class
# __import__ is handled in a special way
def custom_import(name, globals, locals, fromlist, level):
print('import', name, fromlist, level)
class M:
a = 1
b = 2
return M
Reported by Pylint.
tests/micropython/heapalloc.py
30 issues
Line: 3
Column: 1
# check that we can do certain things without allocating heap memory
import micropython
# Check for stackless build, which can't call functions without
# allocating a frame on heap.
try:
def stackless():
Reported by Pylint.
Line: 17
Column: 5
micropython.heap_unlock()
except RuntimeError:
print("SKIP")
raise SystemExit
def f1(a):
print(a)
Reported by Pylint.
Line: 40
Column: 5
def test():
global global_var, global_exc
global_var = 2 # set an existing global variable
for i in range(2): # for loop
f1(i) # function call
f1(i * 2 + 1) # binary operation with small ints
f1(a=i) # keyword arguments
Reported by Pylint.
Line: 1
Column: 1
# check that we can do certain things without allocating heap memory
import micropython
# Check for stackless build, which can't call functions without
# allocating a frame on heap.
try:
def stackless():
Reported by Pylint.
Line: 9
Column: 5
# allocating a frame on heap.
try:
def stackless():
pass
micropython.heap_lock()
stackless()
micropython.heap_unlock()
Reported by Pylint.
Line: 20
Column: 1
raise SystemExit
def f1(a):
print(a)
def f2(a, b=2):
print(a, b)
Reported by Pylint.
Line: 20
Column: 1
raise SystemExit
def f1(a):
print(a)
def f2(a, b=2):
print(a, b)
Reported by Pylint.
Line: 20
Column: 1
raise SystemExit
def f1(a):
print(a)
def f2(a, b=2):
print(a, b)
Reported by Pylint.
Line: 24
Column: 1
print(a)
def f2(a, b=2):
print(a, b)
def f3(a, b, c, d):
x1 = x2 = a
Reported by Pylint.
Line: 24
Column: 1
print(a)
def f2(a, b=2):
print(a, b)
def f3(a, b, c, d):
x1 = x2 = a
Reported by Pylint.
extmod/webrepl/webrepl.py
30 issues
Line: 3
Column: 1
# This module should be imported from REPL, not run from command line.
import socket
import uos
import network
import uwebsocket
import websocket_helper
import _webrepl
listen_s = None
Reported by Pylint.
Line: 4
Column: 1
# This module should be imported from REPL, not run from command line.
import socket
import uos
import network
import uwebsocket
import websocket_helper
import _webrepl
listen_s = None
Reported by Pylint.
Line: 5
Column: 1
import socket
import uos
import network
import uwebsocket
import websocket_helper
import _webrepl
listen_s = None
client_s = None
Reported by Pylint.
Line: 7
Column: 1
import network
import uwebsocket
import websocket_helper
import _webrepl
listen_s = None
client_s = None
Reported by Pylint.
Line: 66
Column: 13
stop()
if password is None:
try:
import webrepl_cfg
_webrepl.password(webrepl_cfg.PASS)
setup_conn(port, accept_conn)
print("Started webrepl in normal mode")
except:
Reported by Pylint.
Line: 14
Column: 5
def setup_conn(port, accept_handler):
global listen_s
listen_s = socket.socket()
listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ai = socket.getaddrinfo("0.0.0.0", port)
addr = ai[0][4]
Reported by Pylint.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html
listen_s = socket.socket()
listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ai = socket.getaddrinfo("0.0.0.0", port)
addr = ai[0][4]
listen_s.bind(addr)
listen_s.listen(1)
if accept_handler:
Reported by Bandit.
Line: 33
Column: 5
def accept_conn(listen_sock):
global client_s
cl, remote_addr = listen_sock.accept()
prev = uos.dupterm(None)
uos.dupterm(prev)
if prev:
print("\nConcurrent WebREPL connection from", remote_addr, "rejected")
Reported by Pylint.
Line: 45
Column: 10
client_s = cl
websocket_helper.server_handshake(cl)
ws = uwebsocket.websocket(cl, True)
ws = _webrepl._webrepl(ws)
cl.setblocking(False)
# notify REPL on socket incoming data (ESP32/ESP8266-only)
if hasattr(uos, "dupterm_notify"):
cl.setsockopt(socket.SOL_SOCKET, 20, uos.dupterm_notify)
uos.dupterm(ws)
Reported by Pylint.
Line: 54
Column: 5
def stop():
global listen_s, client_s
uos.dupterm(None)
if client_s:
client_s.close()
if listen_s:
listen_s.close()
Reported by Pylint.
tests/inlineasm/asmfpsqrt.py
30 issues
Line: 2
Column: 2
# test vsqrt, vneg
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
Reported by Pylint.
Line: 4
Column: 5
# test vsqrt, vneg
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
Reported by Pylint.
Line: 4
Column: 10
# test vsqrt, vneg
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
Reported by Pylint.
Line: 5
Column: 22
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
vneg(s7, s0)
Reported by Pylint.
Line: 5
Column: 5
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
vneg(s7, s0)
Reported by Pylint.
Line: 5
Column: 18
@micropython.asm_thumb # r0 = -(int)(sqrt(r0)*r1)
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
vneg(s7, s0)
Reported by Pylint.
Line: 6
Column: 11
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
vneg(s7, s0)
vcvt_s32_f32(s31, s7)
Reported by Pylint.
Line: 6
Column: 15
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
vneg(s7, s0)
vcvt_s32_f32(s31, s7)
Reported by Pylint.
Line: 6
Column: 5
def sqrt_test(r0, r1):
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
vneg(s7, s0)
vcvt_s32_f32(s31, s7)
Reported by Pylint.
Line: 7
Column: 10
vmov(s1, r0)
vcvt_f32_s32(s1, s1)
vsqrt(s1, s1)
vmov(s2, r1)
vcvt_f32_s32(s2, s2)
vmul(s0, s1, s2)
vneg(s7, s0)
vcvt_s32_f32(s31, s7)
vmov(r0, s31)
Reported by Pylint.
tests/net_inet/getaddrinfo.py
29 issues
Line: 2
Column: 5
try:
import usocket as socket, sys
except:
import socket, sys
def test_non_existent():
try:
res = socket.getaddrinfo("nonexistent.example.com", 80)
Reported by Pylint.
Line: 3
Column: 1
try:
import usocket as socket, sys
except:
import socket, sys
def test_non_existent():
try:
res = socket.getaddrinfo("nonexistent.example.com", 80)
Reported by Pylint.
Line: 11
Column: 5
try:
res = socket.getaddrinfo("nonexistent.example.com", 80)
print("getaddrinfo returned", res)
except OSError as e:
print("getaddrinfo raised")
def test_bogus():
try:
Reported by Pylint.
Line: 19
Column: 5
try:
res = socket.getaddrinfo("hey.!!$$", 80)
print("getaddrinfo returned", res)
except OSError as e:
print("getaddrinfo raised")
except Exception as e:
print("getaddrinfo raised") # CPython raises UnicodeError!?
Reported by Pylint.
Line: 21
Column: 12
print("getaddrinfo returned", res)
except OSError as e:
print("getaddrinfo raised")
except Exception as e:
print("getaddrinfo raised") # CPython raises UnicodeError!?
def test_ip_addr():
try:
Reported by Pylint.
Line: 27
Column: 9
def test_ip_addr():
try:
res = socket.getaddrinfo("10.10.10.10", 80)
print("getaddrinfo returned resolutions")
except Exception as e:
print("getaddrinfo raised", e)
Reported by Pylint.
Line: 29
Column: 12
try:
res = socket.getaddrinfo("10.10.10.10", 80)
print("getaddrinfo returned resolutions")
except Exception as e:
print("getaddrinfo raised", e)
def test_0_0_0_0():
try:
Reported by Pylint.
Line: 35
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html
def test_0_0_0_0():
try:
res = socket.getaddrinfo("0.0.0.0", 80)
print("getaddrinfo returned resolutions")
except Exception as e:
print("getaddrinfo raised", e)
Reported by Bandit.
Line: 35
Column: 9
def test_0_0_0_0():
try:
res = socket.getaddrinfo("0.0.0.0", 80)
print("getaddrinfo returned resolutions")
except Exception as e:
print("getaddrinfo raised", e)
Reported by Pylint.
Line: 37
Column: 12
try:
res = socket.getaddrinfo("0.0.0.0", 80)
print("getaddrinfo returned resolutions")
except Exception as e:
print("getaddrinfo raised", e)
def test_valid():
try:
Reported by Pylint.
examples/bluetooth/ble_bonding_peripheral.py
29 issues
Line: 8
Column: 1
#
# Work-in-progress demo of implementing bonding and passkey auth.
import bluetooth
import random
import struct
import time
import json
import binascii
Reported by Pylint.
Line: 16
Column: 1
import binascii
from ble_advertising import advertising_payload
from micropython import const
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_GATTS_INDICATE_DONE = const(20)
Reported by Pylint.
Line: 190
Column: 9
temp.set_temperature(t, notify=i == 0, indicate=False)
# Random walk the temperature.
t += random.uniform(-0.5, 0.5)
time.sleep_ms(1000)
if __name__ == "__main__":
demo()
Reported by Pylint.
Line: 108
Column: 26
else:
print("unknown action")
elif event == _IRQ_GATTS_INDICATE_DONE:
conn_handle, value_handle, status = data
elif event == _IRQ_SET_SECRET:
sec_type, key, value = data
key = sec_type, bytes(key)
value = bytes(value) if value else None
print("set secret:", key, value)
Reported by Pylint.
Line: 108
Column: 40
else:
print("unknown action")
elif event == _IRQ_GATTS_INDICATE_DONE:
conn_handle, value_handle, status = data
elif event == _IRQ_SET_SECRET:
sec_type, key, value = data
key = sec_type, bytes(key)
value = bytes(value) if value else None
print("set secret:", key, value)
Reported by Pylint.
Line: 162
Column: 9
entries = json.load(f)
for sec_type, key, value in entries:
self._secrets[sec_type, binascii.a2b_base64(key)] = binascii.a2b_base64(value)
except:
print("no secrets available")
def _save_secrets(self):
try:
with open("secrets.json", "w") as f:
Reported by Pylint.
Line: 173
Column: 9
for (sec_type, key), value in self._secrets.items()
]
json.dump(json_secrets, f)
except:
print("failed to save secrets")
def demo():
ble = bluetooth.BLE()
Reported by Pylint.
Line: 1
Column: 1
# This example demonstrates a simple temperature sensor peripheral.
#
# The sensor's local value updates every second, and it will notify
# any connected central every 10 seconds.
#
# Work-in-progress demo of implementing bonding and passkey auth.
import bluetooth
import random
Reported by Pylint.
Line: 9
Column: 1
# Work-in-progress demo of implementing bonding and passkey auth.
import bluetooth
import random
import struct
import time
import json
import binascii
from ble_advertising import advertising_payload
Reported by Pylint.
Line: 10
Column: 1
import bluetooth
import random
import struct
import time
import json
import binascii
from ble_advertising import advertising_payload
Reported by Pylint.
tests/basics/scope.py
29 issues
Line: 13
Column: 1
print(a)
# explicit nonlocal variable
def f():
a = 1
def g():
nonlocal a
nonlocal a, a # should be able to redefine as nonlocal
a = 2
Reported by Pylint.
Line: 24
Column: 1
print(f())
# nonlocal at inner-inner level (h)
def f():
x = 1
def g():
def h():
nonlocal x
return x
Reported by Pylint.
Line: 35
Column: 1
print(f()()())
# nonlocal declared at outer level (g), and referenced by inner level (h)
def f():
x = 1
def g():
nonlocal x
def h():
return x
Reported by Pylint.
Line: 6
Column: 5
# explicit global variable
a = 1
def f():
global a
global a, a # should be able to redefine as global
a = 2
f()
print(a)
Reported by Pylint.
Line: 7
Column: 5
a = 1
def f():
global a
global a, a # should be able to redefine as global
a = 2
f()
print(a)
# explicit nonlocal variable
Reported by Pylint.
Line: 14
Column: 5
# explicit nonlocal variable
def f():
a = 1
def g():
nonlocal a
nonlocal a, a # should be able to redefine as nonlocal
a = 2
g()
Reported by Pylint.
Line: 18
Column: 9
def g():
nonlocal a
nonlocal a, a # should be able to redefine as nonlocal
a = 2
g()
return a
print(f())
# nonlocal at inner-inner level (h)
Reported by Pylint.
Line: 1
Column: 1
# test scoping rules
# explicit global variable
a = 1
def f():
global a
global a, a # should be able to redefine as global
a = 2
f()
Reported by Pylint.
Line: 4
Column: 1
# test scoping rules
# explicit global variable
a = 1
def f():
global a
global a, a # should be able to redefine as global
a = 2
f()
Reported by Pylint.
Line: 5
Column: 1
# explicit global variable
a = 1
def f():
global a
global a, a # should be able to redefine as global
a = 2
f()
print(a)
Reported by Pylint.
tests/wipy/wlan/wlan.py
29 issues
Line: 5
Column: 1
WLAN test for the CC3200 based boards.
"""
from network import WLAN
import os
import time
import testconfig
mch = os.uname().machine
Reported by Pylint.
Line: 8
Column: 1
from network import WLAN
import os
import time
import testconfig
mch = os.uname().machine
if not "LaunchPad" in mch and not "WiPy" in mch:
raise Exception("Board not supported!")
Reported by Pylint.
Line: 97
Column: 6
wifi.disconnect()
print(wifi.isconnected() == False)
t0 = time.ticks_ms()
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=0)
print(time.ticks_ms() - t0 < 500)
wifi.disconnect()
print(wifi.isconnected() == False)
Reported by Pylint.
Line: 99
Column: 7
t0 = time.ticks_ms()
wifi.connect(testconfig.wlan_ssid, auth=testconfig.wlan_auth, timeout=0)
print(time.ticks_ms() - t0 < 500)
wifi.disconnect()
print(wifi.isconnected() == False)
# test init again
Reported by Pylint.
Line: 15
Column: 25
raise Exception("Board not supported!")
def wait_for_connection(wifi, timeout=10):
while not wifi.isconnected() and timeout > 0:
time.sleep(1)
timeout -= 1
if wifi.isconnected():
print("Connected")
Reported by Pylint.
Line: 87
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html
wifi.ifconfig(config="dhcp")
wait_for_connection(wifi)
print("0.0.0.0" not in wifi.ifconfig())
wifi.ifconfig(0, ("192.168.178.109", "255.255.255.0", "192.168.178.1", "8.8.8.8"))
wait_for_connection(wifi)
print(wifi.ifconfig(0) == ("192.168.178.109", "255.255.255.0", "192.168.178.1", "8.8.8.8"))
wait_for_connection(wifi)
Reported by Bandit.
Line: 120
Column: 1
# next ones MUST raise
try:
wifi.init(mode=12345)
except:
print("Exception")
try:
wifi.init(1, mode=WLAN.AP)
except:
Reported by Pylint.
Line: 125
Column: 1
try:
wifi.init(1, mode=WLAN.AP)
except:
print("Exception")
try:
wifi.init(mode=WLAN.AP, ssid=None)
except:
Reported by Pylint.
Line: 130
Column: 1
try:
wifi.init(mode=WLAN.AP, ssid=None)
except:
print("Exception")
try:
wifi = WLAN(mode=WLAN.AP, channel=12)
except:
Reported by Pylint.
Line: 135
Column: 1
try:
wifi = WLAN(mode=WLAN.AP, channel=12)
except:
print("Exception")
try:
wifi.antenna(2)
except:
Reported by Pylint.