The following issues were found
tests/cpydiff/core_locals_eval.py
6 issues
Line: 11
Column: 5
def test():
val = 2
print(val)
eval("print(val)")
test()
Reported by Pylint.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
def test():
val = 2
print(val)
eval("print(val)")
test()
Reported by Bandit.
Line: 13
Column: 5
def test():
val = 2
print(val)
eval("print(val)")
test()
Reported by Pylint.
Line: 4
Column: 1
"""
categories: Core,Runtime
description: Code running in eval() function doesn't have access to local variables
cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name. Effectively, ``eval(expr)`` in MicroPython is equivalent to ``eval(expr, globals(), globals())``.
workaround: Unknown
"""
val = 1
Reported by Pylint.
Line: 7
Column: 1
cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name. Effectively, ``eval(expr)`` in MicroPython is equivalent to ``eval(expr, globals(), globals())``.
workaround: Unknown
"""
val = 1
def test():
val = 2
print(val)
Reported by Pylint.
Line: 10
Column: 1
val = 1
def test():
val = 2
print(val)
eval("print(val)")
Reported by Pylint.
tests/internal_bench/bytebuf-2-join_map_bytes.py
6 issues
Line: 9
Column: 9
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))
bench.run(test)
Reported by Pylint.
Line: 11
Column: 9
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))
bench.run(test)
Reported by Pylint.
Line: 1
Column: 1
# Doing some operation on bytearray
# Pretty weird way - map bytearray thru function, but make sure that
# function return bytes of size 1, then join them together. Surely,
# this is slowest way to do it.
import bench
def test(num):
for i in iter(range(num // 10000)):
Reported by Pylint.
Line: 1
Column: 1
# Doing some operation on bytearray
# Pretty weird way - map bytearray thru function, but make sure that
# function return bytes of size 1, then join them together. Surely,
# this is slowest way to do it.
import bench
def test(num):
for i in iter(range(num // 10000)):
Reported by Pylint.
Line: 8
Column: 1
import bench
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))
Reported by Pylint.
Line: 10
Column: 9
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))
bench.run(test)
Reported by Pylint.
tests/thread/thread_lock3.py
6 issues
Line: 13
Column: 5
def thread_entry(idx):
global n_finished
while True:
with lock:
if n_finished == idx:
break
print("my turn:", idx)
Reported by Pylint.
Line: 1
Column: 1
# test thread coordination using a lock object
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
lock = _thread.allocate_lock()
n_thread = 10
n_finished = 0
Reported by Pylint.
Line: 8
Column: 1
import _thread
lock = _thread.allocate_lock()
n_thread = 10
n_finished = 0
def thread_entry(idx):
global n_finished
Reported by Pylint.
Line: 9
Column: 1
lock = _thread.allocate_lock()
n_thread = 10
n_finished = 0
def thread_entry(idx):
global n_finished
while True:
Reported by Pylint.
Line: 12
Column: 1
n_finished = 0
def thread_entry(idx):
global n_finished
while True:
with lock:
if n_finished == idx:
break
Reported by Pylint.
Line: 13
Column: 5
def thread_entry(idx):
global n_finished
while True:
with lock:
if n_finished == idx:
break
print("my turn:", idx)
Reported by Pylint.
tests/basics/string_large.py
6 issues
Line: 2
Column: 1
s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"
Reported by Pylint.
Line: 1
Column: 1
s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"
Reported by Pylint.
Line: 1
Column: 1
s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"
Reported by Pylint.
Line: 1
Column: 1
s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"
Reported by Pylint.
Line: 2
Column: 1
s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"
Reported by Pylint.
Line: 2
Column: 1
s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"
Reported by Pylint.
tests/internal_bench/bytebuf-3-bytarray_map.py
6 issues
Line: 7
Column: 9
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = bytearray(map(lambda x: x + 1, ba))
bench.run(test)
Reported by Pylint.
Line: 9
Column: 9
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = bytearray(map(lambda x: x + 1, ba))
bench.run(test)
Reported by Pylint.
Line: 1
Column: 1
# Doing some operation on bytearray
# No joins, but still map().
import bench
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = bytearray(map(lambda x: x + 1, ba))
Reported by Pylint.
Line: 1
Column: 1
# Doing some operation on bytearray
# No joins, but still map().
import bench
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = bytearray(map(lambda x: x + 1, ba))
Reported by Pylint.
Line: 6
Column: 1
import bench
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = bytearray(map(lambda x: x + 1, ba))
Reported by Pylint.
Line: 8
Column: 9
def test(num):
for i in iter(range(num // 10000)):
ba = bytearray(b"\0" * 1000)
ba2 = bytearray(map(lambda x: x + 1, ba))
bench.run(test)
Reported by Pylint.
tests/extmod/ussl_basic.py
6 issues
Line: 8
Column: 5
import ussl as ssl
except ImportError:
print("SKIP")
raise SystemExit
# create in client mode
try:
ss = ssl.wrap_socket(io.BytesIO(), server_hostname="test.example.com")
except OSError as er:
Reported by Pylint.
Line: 1
Column: 1
# very basic test of ssl module, just to test the methods exist
try:
import uio as io
import ussl as ssl
except ImportError:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 13
Column: 1
# create in client mode
try:
ss = ssl.wrap_socket(io.BytesIO(), server_hostname="test.example.com")
except OSError as er:
print("wrap_socket:", repr(er))
# create in server mode (can use this object for further tests)
socket = io.BytesIO()
ss = ssl.wrap_socket(socket, server_side=1)
Reported by Pylint.
Line: 42
Column: 1
socket.seek(0)
try:
ss.read(8)
except OSError as er:
print("read:", repr(er))
# close
ss.close()
# close 2nd time
Reported by Pylint.
Line: 53
Column: 1
# read on closed socket
try:
ss.read(10)
except OSError as er:
print("read:", repr(er))
# write on closed socket
try:
ss.write(b"aaaa")
Reported by Pylint.
Line: 59
Column: 1
# write on closed socket
try:
ss.write(b"aaaa")
except OSError as er:
print("write:", repr(er))
Reported by Pylint.
tests/basics/slots_bool_len.py
6 issues
Line: 1
Column: 1
class A:
def __bool__(self):
print('__bool__')
return True
def __len__(self):
print('__len__')
return 1
class B:
Reported by Pylint.
Line: 1
Column: 1
class A:
def __bool__(self):
print('__bool__')
return True
def __len__(self):
print('__len__')
return 1
class B:
Reported by Pylint.
Line: 1
Column: 1
class A:
def __bool__(self):
print('__bool__')
return True
def __len__(self):
print('__len__')
return 1
class B:
Reported by Pylint.
Line: 9
Column: 1
print('__len__')
return 1
class B:
def __len__(self):
print('__len__')
return 0
print(bool(A()))
Reported by Pylint.
Line: 9
Column: 1
print('__len__')
return 1
class B:
def __len__(self):
print('__len__')
return 0
print(bool(A()))
Reported by Pylint.
Line: 9
Column: 1
print('__len__')
return 1
class B:
def __len__(self):
print('__len__')
return 0
print(bool(A()))
Reported by Pylint.
tests/micropython/viper_error.py
6 issues
Line: 7
Column: 26
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
print(repr(e))
# viper: annotations must be identifiers
test("@micropython.viper\ndef f(a:1): pass")
Reported by Pylint.
Line: 6
Column: 9
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
print(repr(e))
# viper: annotations must be identifiers
Reported by Pylint.
Line: 6
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
print(repr(e))
# viper: annotations must be identifiers
Reported by Bandit.
Line: 1
Column: 1
# test syntax and type errors specific to viper code generation
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
print(repr(e))
Reported by Pylint.
Line: 4
Column: 1
# test syntax and type errors specific to viper code generation
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
print(repr(e))
Reported by Pylint.
Line: 7
Column: 5
def test(code):
try:
exec(code)
except (SyntaxError, ViperTypeError, NotImplementedError) as e:
print(repr(e))
# viper: annotations must be identifiers
test("@micropython.viper\ndef f(a:1): pass")
Reported by Pylint.
tests/basics/try_reraise.py
6 issues
Line: 17
Column: 5
# Can reraise only in except block
try:
raise
except RuntimeError:
print("RuntimeError")
Reported by Pylint.
Line: 6
Column: 5
def f():
try:
raise ValueError("val", 3)
except:
raise
try:
f()
except ValueError as e:
Reported by Pylint.
Line: 1
Column: 1
# Reraising last exception with raise w/o args
def f():
try:
raise ValueError("val", 3)
except:
raise
try:
Reported by Pylint.
Line: 3
Column: 1
# Reraising last exception with raise w/o args
def f():
try:
raise ValueError("val", 3)
except:
raise
try:
Reported by Pylint.
Line: 3
Column: 1
# Reraising last exception with raise w/o args
def f():
try:
raise ValueError("val", 3)
except:
raise
try:
Reported by Pylint.
Line: 11
Column: 1
try:
f()
except ValueError as e:
print(repr(e))
# Can reraise only in except block
try:
Reported by Pylint.
tests/thread/stress_create.py
6 issues
Line: 14
Column: 18
import _thread
def thread_entry(n):
pass
thread_num = 0
while thread_num < 500:
Reported by Pylint.
Line: 1
Column: 1
# stress test for creating many threads
try:
import utime
sleep_ms = utime.sleep_ms
except ImportError:
import time
Reported by Pylint.
Line: 14
Column: 1
import _thread
def thread_entry(n):
pass
thread_num = 0
while thread_num < 500:
Reported by Pylint.
Line: 14
Column: 1
import _thread
def thread_entry(n):
pass
thread_num = 0
while thread_num < 500:
Reported by Pylint.
Line: 18
Column: 1
pass
thread_num = 0
while thread_num < 500:
try:
_thread.start_new_thread(thread_entry, (thread_num,))
thread_num += 1
except (MemoryError, OSError) as er:
Reported by Pylint.
Line: 23
Column: 5
try:
_thread.start_new_thread(thread_entry, (thread_num,))
thread_num += 1
except (MemoryError, OSError) as er:
# Cannot create a new thead at this stage, yield for a bit to
# let existing threads run to completion and free up resources.
sleep_ms(50)
# wait for the last threads to terminate
Reported by Pylint.