The following issues were found
tests/thread/thread_shared1.py
15 issues
Line: 17
Column: 9
foo(i)
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 2
n_finished = 0
Reported by Pylint.
Line: 8
Column: 9
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
Reported by Pylint.
Line: 8
Column: 9
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
Reported by Pylint.
Line: 12
Column: 18
pass
def thread_entry(n, tup):
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 12
Column: 21
pass
def thread_entry(n, tup):
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 13
Column: 9
def thread_entry(n, tup):
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 16
Column: 9
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 2
Reported by Pylint.
Line: 1
Column: 1
# test capability for threads to access a shared immutable data structure
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def foo(i):
pass
Reported by Pylint.
Line: 8
Column: 1
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
Reported by Pylint.
Line: 8
Column: 1
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
Reported by Pylint.
tests/thread/thread_shared2.py
15 issues
Line: 18
Column: 9
foo(lst, idx)
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 2
n_finished = 0
Reported by Pylint.
Line: 9
Column: 14
import _thread
def foo(lst, i):
lst[i] += 1
def thread_entry(n, lst, idx):
for i in range(n):
Reported by Pylint.
Line: 9
Column: 9
import _thread
def foo(lst, i):
lst[i] += 1
def thread_entry(n, lst, idx):
for i in range(n):
Reported by Pylint.
Line: 13
Column: 21
lst[i] += 1
def thread_entry(n, lst, idx):
for i in range(n):
foo(lst, idx)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 14
Column: 9
def thread_entry(n, lst, idx):
for i in range(n):
foo(lst, idx)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 14
Column: 9
def thread_entry(n, lst, idx):
for i in range(n):
foo(lst, idx)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 17
Column: 9
for i in range(n):
foo(lst, idx)
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 2
Reported by Pylint.
Line: 1
Column: 1
# test capability for threads to access a shared mutable data structure
# (without contention because they access different parts of the structure)
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def foo(lst, i):
Reported by Pylint.
Line: 9
Column: 1
import _thread
def foo(lst, i):
lst[i] += 1
def thread_entry(n, lst, idx):
for i in range(n):
Reported by Pylint.
Line: 9
Column: 1
import _thread
def foo(lst, i):
lst[i] += 1
def thread_entry(n, lst, idx):
for i in range(n):
Reported by Pylint.
tests/misc/sys_settrace_generator.py
15 issues
Line: 9
Column: 5
sys.settrace
except AttributeError:
print("SKIP")
raise SystemExit
def print_stacktrace(frame, level=0):
print(
"%2d: %s@%s:%s => %s:%d"
Reported by Pylint.
Line: 33
Column: 38
trace_count = 0
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
trace_count += 1
print_stacktrace(frame)
return trace_tick_handler
Reported by Pylint.
Line: 34
Column: 5
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
trace_count += 1
print_stacktrace(frame)
return trace_tick_handler
Reported by Pylint.
Line: 1
Column: 1
# test sys.settrace with generators
import sys
try:
sys.settrace
except AttributeError:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 12
Column: 1
raise SystemExit
def print_stacktrace(frame, level=0):
print(
"%2d: %s@%s:%s => %s:%d"
% (
level,
" ",
Reported by Pylint.
Line: 30
Column: 1
print_stacktrace(frame.f_back, level + 1)
trace_count = 0
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
Reported by Pylint.
Line: 33
Column: 1
trace_count = 0
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
trace_count += 1
print_stacktrace(frame)
return trace_tick_handler
Reported by Pylint.
Line: 34
Column: 5
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
trace_count += 1
print_stacktrace(frame)
return trace_tick_handler
Reported by Pylint.
Line: 41
Column: 1
return trace_tick_handler
def test_generator():
def make_gen():
yield 1 << 0
yield 1 << 1
yield 1 << 2
return 1 << 3
Reported by Pylint.
Line: 49
Column: 5
return 1 << 3
gen = make_gen()
r = 0
try:
r += gen.send(None)
while True:
Reported by Pylint.
tests/net_inet/tls_num_errors.py
15 issues
Line: 8
Column: 5
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 4
Column: 5
# test that modtls produces a numerical error message when out of heap
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
Reported by Pylint.
Line: 5
Column: 1
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
Reported by Pylint.
Line: 11
Column: 5
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
# test with heap locked to see it switch to number-only error message
def test(addr):
alloc_emergency_exception_buf(256)
Reported by Pylint.
Line: 15
Column: 10
# test with heap locked to see it switch to number-only error message
def test(addr):
alloc_emergency_exception_buf(256)
s = socket.socket()
s.connect(addr)
try:
s.setblocking(False)
Reported by Pylint.
Line: 21
Column: 13
s.connect(addr)
try:
s.setblocking(False)
s = ssl.wrap_socket(s, do_handshake=False)
heap_lock()
print("heap is locked")
while True:
ret = s.write("foo")
if ret:
Reported by Pylint.
Line: 1
Column: 1
# test that modtls produces a numerical error message when out of heap
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
Reported by Pylint.
Line: 4
Column: 5
# test that modtls produces a numerical error message when out of heap
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
Reported by Pylint.
Line: 6
Column: 5
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 6
Column: 5
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
Reported by Pylint.
tests/extmod/uasyncio_cancel_task.py
15 issues
Line: 10
Column: 9
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(s, allow_cancel):
try:
print("task start")
Reported by Pylint.
Line: 1
Column: 1
# Test cancelling a task
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
async def task(s, allow_cancel):
try:
print("task start")
await asyncio.sleep(s)
print("task done")
except asyncio.CancelledError as er:
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
async def task(s, allow_cancel):
try:
print("task start")
await asyncio.sleep(s)
print("task done")
except asyncio.CancelledError as er:
Reported by Pylint.
Line: 18
Column: 5
print("task start")
await asyncio.sleep(s)
print("task done")
except asyncio.CancelledError as er:
print("task cancel")
if allow_cancel:
raise er
Reported by Pylint.
Line: 24
Column: 1
raise er
async def task2(allow_cancel):
print("task 2")
try:
await asyncio.create_task(task(0.05, allow_cancel))
except asyncio.CancelledError as er:
print("task 2 cancel")
Reported by Pylint.
Line: 28
Column: 5
print("task 2")
try:
await asyncio.create_task(task(0.05, allow_cancel))
except asyncio.CancelledError as er:
print("task 2 cancel")
raise er
print("task 2 done")
Reported by Pylint.
Line: 34
Column: 1
print("task 2 done")
async def main():
# Cancel task immediately
t = asyncio.create_task(task(2, True))
print(t.cancel())
# Cancel task after it has started
Reported by Pylint.
Line: 36
Column: 5
async def main():
# Cancel task immediately
t = asyncio.create_task(task(2, True))
print(t.cancel())
# Cancel task after it has started
t = asyncio.create_task(task(2, True))
await asyncio.sleep(0.01)
Reported by Pylint.
Line: 40
Column: 5
print(t.cancel())
# Cancel task after it has started
t = asyncio.create_task(task(2, True))
await asyncio.sleep(0.01)
print(t.cancel())
print("main sleep")
await asyncio.sleep(0.01)
Reported by Pylint.
tools/metrics.py
15 issues
Line: 52
Column: 30
class PortData:
def __init__(self, name, dir, output, make_flags=None):
self.name = name
self.dir = dir
self.output = output
self.make_flags = make_flags
self.needs_mpy_cross = dir not in ("bare-arm", "minimal")
Reported by Pylint.
Line: 46
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
"""
import collections, sys, re, subprocess
MAKE_FLAGS = ["-j3", "CFLAGS_EXTRA=-DNDEBUG"]
class PortData:
Reported by Bandit.
Line: 46
Column: 1
"""
import collections, sys, re, subprocess
MAKE_FLAGS = ["-j3", "CFLAGS_EXTRA=-DNDEBUG"]
class PortData:
Reported by Pylint.
Line: 51
Column: 1
MAKE_FLAGS = ["-j3", "CFLAGS_EXTRA=-DNDEBUG"]
class PortData:
def __init__(self, name, dir, output, make_flags=None):
self.name = name
self.dir = dir
self.output = output
self.make_flags = make_flags
Reported by Pylint.
Line: 51
Column: 1
MAKE_FLAGS = ["-j3", "CFLAGS_EXTRA=-DNDEBUG"]
class PortData:
def __init__(self, name, dir, output, make_flags=None):
self.name = name
self.dir = dir
self.output = output
self.make_flags = make_flags
Reported by Pylint.
Line: 75
Column: 1
}
def syscmd(*args):
sys.stdout.flush()
a2 = []
for a in args:
if isinstance(a, str):
a2.append(a)
Reported by Pylint.
Line: 77
Column: 5
def syscmd(*args):
sys.stdout.flush()
a2 = []
for a in args:
if isinstance(a, str):
a2.append(a)
elif a:
a2.extend(a)
Reported by Pylint.
Line: 78
Column: 9
def syscmd(*args):
sys.stdout.flush()
a2 = []
for a in args:
if isinstance(a, str):
a2.append(a)
elif a:
a2.extend(a)
subprocess.check_call(a2)
Reported by Pylint.
Line: 83
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html
a2.append(a)
elif a:
a2.extend(a)
subprocess.check_call(a2)
def parse_port_list(args):
if not args:
return list(port_data.values())
Reported by Bandit.
Line: 86
Column: 1
subprocess.check_call(a2)
def parse_port_list(args):
if not args:
return list(port_data.values())
else:
ports = []
for arg in args:
Reported by Pylint.
examples/bluetooth/ble_uart_peripheral.py
14 issues
Line: 3
Column: 1
# This example demonstrates a peripheral implementing the Nordic UART Service (NUS).
import bluetooth
from ble_advertising import advertising_payload
from micropython import const
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
Reported by Pylint.
Line: 6
Column: 1
import bluetooth
from ble_advertising import advertising_payload
from micropython import const
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_GATTS_WRITE = const(3)
Reported by Pylint.
Line: 109
Column: 13
while True:
uart.write(str(nums[i]) + "\n")
i = (i + 1) % len(nums)
time.sleep_ms(1000)
except KeyboardInterrupt:
pass
uart.close()
Reported by Pylint.
Line: 1
Column: 1
# This example demonstrates a peripheral implementing the Nordic UART Service (NUS).
import bluetooth
from ble_advertising import advertising_payload
from micropython import const
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
Reported by Pylint.
Line: 6
Column: 1
import bluetooth
from ble_advertising import advertising_payload
from micropython import const
_IRQ_CENTRAL_CONNECT = const(1)
_IRQ_CENTRAL_DISCONNECT = const(2)
_IRQ_GATTS_WRITE = const(3)
Reported by Pylint.
Line: 33
Column: 1
_ADV_APPEARANCE_GENERIC_COMPUTER = const(128)
class BLEUART:
def __init__(self, ble, name="mpy-uart", rxbuf=100):
self._ble = ble
self._ble.active(True)
self._ble.irq(self._irq)
((self._tx_handle, self._rx_handle),) = self._ble.gatts_register_services((_UART_SERVICE,))
Reported by Pylint.
Line: 48
Column: 5
self._payload = advertising_payload(name=name, appearance=_ADV_APPEARANCE_GENERIC_COMPUTER)
self._advertise()
def irq(self, handler):
self._handler = handler
def _irq(self, event, data):
# Track connections so we can send notifications.
if event == _IRQ_CENTRAL_CONNECT:
Reported by Pylint.
Line: 69
Column: 5
if self._handler:
self._handler()
def any(self):
return len(self._rx_buffer)
def read(self, sz=None):
if not sz:
sz = len(self._rx_buffer)
Reported by Pylint.
Line: 72
Column: 5
def any(self):
return len(self._rx_buffer)
def read(self, sz=None):
if not sz:
sz = len(self._rx_buffer)
result = self._rx_buffer[0:sz]
self._rx_buffer = self._rx_buffer[sz:]
return result
Reported by Pylint.
Line: 72
Column: 5
def any(self):
return len(self._rx_buffer)
def read(self, sz=None):
if not sz:
sz = len(self._rx_buffer)
result = self._rx_buffer[0:sz]
self._rx_buffer = self._rx_buffer[sz:]
return result
Reported by Pylint.
tests/micropython/viper_with.py
14 issues
Line: 16
Column: 2
# basic with
@micropython.viper
def f():
with C():
print(1)
Reported by Pylint.
Line: 25
Column: 2
f()
# nested with and try-except
@micropython.viper
def f():
try:
with C():
print(1)
fail
Reported by Pylint.
Line: 26
Column: 1
# nested with and try-except
@micropython.viper
def f():
try:
with C():
print(1)
fail
print(2)
Reported by Pylint.
Line: 30
Column: 13
try:
with C():
print(1)
fail
print(2)
except NameError:
print("NameError")
Reported by Pylint.
Line: 1
Column: 1
# test with handling within a viper function
class C:
def __init__(self):
print("__init__")
def __enter__(self):
print("__enter__")
Reported by Pylint.
Line: 4
Column: 1
# test with handling within a viper function
class C:
def __init__(self):
print("__init__")
def __enter__(self):
print("__enter__")
Reported by Pylint.
Line: 4
Column: 1
# test with handling within a viper function
class C:
def __init__(self):
print("__init__")
def __enter__(self):
print("__enter__")
Reported by Pylint.
Line: 11
Column: 5
def __enter__(self):
print("__enter__")
def __exit__(self, a, b, c):
print("__exit__", a, b, c)
# basic with
@micropython.viper
Reported by Pylint.
Line: 11
Column: 5
def __enter__(self):
print("__enter__")
def __exit__(self, a, b, c):
print("__exit__", a, b, c)
# basic with
@micropython.viper
Reported by Pylint.
Line: 11
Column: 5
def __enter__(self):
print("__enter__")
def __exit__(self, a, b, c):
print("__exit__", a, b, c)
# basic with
@micropython.viper
Reported by Pylint.
tests/thread/stress_heap.py
14 issues
Line: 36
Column: 9
with lock:
print(sum, lst[-1])
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 10
n_finished = 0
Reported by Pylint.
Line: 23
Column: 5
# run a loop which allocates a small list and uses it each iteration
lst = 8 * [0]
sum = 0
for i in range(n):
sum += last(lst)
lst = [0, 0, 0, 0, 0, 0, 0, i + 1]
# check that the bytearray still has the right data
Reported by Pylint.
Line: 24
Column: 9
# run a loop which allocates a small list and uses it each iteration
lst = 8 * [0]
sum = 0
for i in range(n):
sum += last(lst)
lst = [0, 0, 0, 0, 0, 0, 0, i + 1]
# check that the bytearray still has the right data
for i, b in enumerate(data):
Reported by Pylint.
Line: 35
Column: 9
# print the result of the loop and indicate we are finished
with lock:
print(sum, lst[-1])
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 10
Reported by Pylint.
Line: 1
Column: 1
# stress test for the heap by allocating lots of objects within threads
# allocates about 5mb on the heap
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
try:
import utime as time
except ImportError:
import time
Reported by Pylint.
Line: 13
Column: 1
import _thread
def last(l):
return l[-1]
def thread_entry(n):
# allocate a bytearray and fill it
Reported by Pylint.
Line: 13
Column: 1
import _thread
def last(l):
return l[-1]
def thread_entry(n):
# allocate a bytearray and fill it
Reported by Pylint.
Line: 17
Column: 1
return l[-1]
def thread_entry(n):
# allocate a bytearray and fill it
data = bytearray(i for i in range(256))
# run a loop which allocates a small list and uses it each iteration
lst = 8 * [0]
Reported by Pylint.
Line: 17
Column: 1
return l[-1]
def thread_entry(n):
# allocate a bytearray and fill it
data = bytearray(i for i in range(256))
# run a loop which allocates a small list and uses it each iteration
lst = 8 * [0]
Reported by Pylint.
Line: 29
Column: 12
lst = [0, 0, 0, 0, 0, 0, 0, i + 1]
# check that the bytearray still has the right data
for i, b in enumerate(data):
assert i == b
# print the result of the loop and indicate we are finished
with lock:
print(sum, lst[-1])
Reported by Pylint.
tests/basics/try_finally1.py
14 issues
Line: 38
Column: 9
print("try1")
try:
print("try2")
foo()
except:
print("except2")
finally:
print("finally1")
print()
Reported by Pylint.
Line: 64
Column: 13
print("try1")
try:
print("try2")
foo()
finally:
print("finally2")
finally:
print("finally1")
except:
Reported by Pylint.
Line: 80
Column: 9
finally:
try:
print("try2")
foo
except:
print("except2")
print("finally1")
print()
Reported by Pylint.
Line: 92
Column: 5
print("try")
finally:
print("finally")
foo
try:
func()
except:
print("except")
Reported by Pylint.
Line: 39
Column: 5
try:
print("try2")
foo()
except:
print("except2")
finally:
print("finally1")
print()
Reported by Pylint.
Line: 69
Column: 1
print("finally2")
finally:
print("finally1")
except:
print("catch-all except")
print()
# case where a try-except within a finally cancels the exception
print("exc-finally-subexcept")
Reported by Pylint.
Line: 80
Column: 9
finally:
try:
print("try2")
foo
except:
print("except2")
print("finally1")
print()
Reported by Pylint.
Line: 81
Column: 5
try:
print("try2")
foo
except:
print("except2")
print("finally1")
print()
# case where exception is raised after a finally has finished (tests that the finally doesn't run again)
Reported by Pylint.
Line: 92
Column: 5
print("try")
finally:
print("finally")
foo
try:
func()
except:
print("except")
Reported by Pylint.
Line: 95
Column: 1
foo
try:
func()
except:
print("except")
Reported by Pylint.