The following issues were found
examples/switch.py
7 issues
Line: 20
Column: 10
import pyb
switch = pyb.Switch()
red_led = pyb.LED(1)
green_led = pyb.LED(2)
orange_led = pyb.LED(3)
blue_led = pyb.LED(4)
all_leds = (red_led, green_led, orange_led, blue_led)
Reported by Pylint.
Line: 21
Column: 11
import pyb
switch = pyb.Switch()
red_led = pyb.LED(1)
green_led = pyb.LED(2)
orange_led = pyb.LED(3)
blue_led = pyb.LED(4)
all_leds = (red_led, green_led, orange_led, blue_led)
Reported by Pylint.
Line: 22
Column: 13
switch = pyb.Switch()
red_led = pyb.LED(1)
green_led = pyb.LED(2)
orange_led = pyb.LED(3)
blue_led = pyb.LED(4)
all_leds = (red_led, green_led, orange_led, blue_led)
Reported by Pylint.
Line: 23
Column: 14
switch = pyb.Switch()
red_led = pyb.LED(1)
green_led = pyb.LED(2)
orange_led = pyb.LED(3)
blue_led = pyb.LED(4)
all_leds = (red_led, green_led, orange_led, blue_led)
def run_loop(leds=all_leds):
Reported by Pylint.
Line: 24
Column: 12
red_led = pyb.LED(1)
green_led = pyb.LED(2)
orange_led = pyb.LED(3)
blue_led = pyb.LED(4)
all_leds = (red_led, green_led, orange_led, blue_led)
def run_loop(leds=all_leds):
"""
Reported by Pylint.
Line: 39
Column: 17
while 1:
try:
if switch():
[led.on() for led in leds]
else:
[led.off() for led in leds]
except OSError: # VCPInterrupt # Ctrl+C in interpreter mode.
break
Reported by Pylint.
Line: 41
Column: 17
if switch():
[led.on() for led in leds]
else:
[led.off() for led in leds]
except OSError: # VCPInterrupt # Ctrl+C in interpreter mode.
break
if __name__ == "__main__":
Reported by Pylint.
tests/unicode/unicode.py
7 issues
Line: 27
Column: 5
# test invalid escape code
try:
eval('"\\U00110000"')
except SyntaxError:
print("SyntaxError")
# test unicode string given to int
try:
Reported by Pylint.
Line: 27
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
# test invalid escape code
try:
eval('"\\U00110000"')
except SyntaxError:
print("SyntaxError")
# test unicode string given to int
try:
Reported by Bandit.
Line: 1
Column: 1
# Test a UTF-8 encoded literal
s = "asdf©qwer"
for i in range(len(s)):
print("s[%d]: %s %X" % (i, s[i], ord(s[i])))
# Test all three forms of Unicode escape, and
# all blocks of UTF-8 byte patterns
s = "a\xA9\xFF\u0123\u0800\uFFEE\U0001F44C"
for i in range(-len(s), len(s)):
Reported by Pylint.
Line: 2
Column: 1
# Test a UTF-8 encoded literal
s = "asdf©qwer"
for i in range(len(s)):
print("s[%d]: %s %X" % (i, s[i], ord(s[i])))
# Test all three forms of Unicode escape, and
# all blocks of UTF-8 byte patterns
s = "a\xA9\xFF\u0123\u0800\uFFEE\U0001F44C"
for i in range(-len(s), len(s)):
Reported by Pylint.
Line: 3
Column: 1
# Test a UTF-8 encoded literal
s = "asdf©qwer"
for i in range(len(s)):
print("s[%d]: %s %X" % (i, s[i], ord(s[i])))
# Test all three forms of Unicode escape, and
# all blocks of UTF-8 byte patterns
s = "a\xA9\xFF\u0123\u0800\uFFEE\U0001F44C"
for i in range(-len(s), len(s)):
Reported by Pylint.
Line: 8
Column: 1
# Test all three forms of Unicode escape, and
# all blocks of UTF-8 byte patterns
s = "a\xA9\xFF\u0123\u0800\uFFEE\U0001F44C"
for i in range(-len(s), len(s)):
print("s[%d]: %s %X" % (i, s[i], ord(s[i])))
print("s[:%d]: %d chars, '%s'" % (i, len(s[:i]), s[:i]))
for j in range(i, len(s)):
print("s[%d:%d]: %d chars, '%s'" % (i, j, len(s[i:j]), s[i:j]))
Reported by Pylint.
Line: 17
Column: 1
print("s[%d:]: %d chars, '%s'" % (i, len(s[i:]), s[i:]))
# Test UTF-8 encode and decode
enc = s.encode()
print(enc, enc.decode() == s)
# printing of unicode chars using repr
# NOTE: for some characters (eg \u10ff) we differ to CPython
print(repr("a\uffff"))
Reported by Pylint.
tests/basics/io_iobase.py
6 issues
Line: 3
Column: 1
try:
import uio as io
except:
import io
try:
io.IOBase
except AttributeError:
print('SKIP')
Reported by Pylint.
Line: 10
Column: 5
io.IOBase
except AttributeError:
print('SKIP')
raise SystemExit
class MyIO(io.IOBase):
def write(self, buf):
# CPython and uPy pass in different types for buf (str vs bytearray)
Reported by Pylint.
Line: 1
Column: 1
try:
import uio as io
except:
import io
try:
io.IOBase
except AttributeError:
print('SKIP')
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
class MyIO(io.IOBase):
def write(self, buf):
# CPython and uPy pass in different types for buf (str vs bytearray)
print('write', len(buf))
return len(buf)
Reported by Pylint.
Line: 14
Column: 5
class MyIO(io.IOBase):
def write(self, buf):
# CPython and uPy pass in different types for buf (str vs bytearray)
print('write', len(buf))
return len(buf)
print('test', file=MyIO())
Reported by Pylint.
Line: 14
Column: 5
class MyIO(io.IOBase):
def write(self, buf):
# CPython and uPy pass in different types for buf (str vs bytearray)
print('write', len(buf))
return len(buf)
print('test', file=MyIO())
Reported by Pylint.
tests/extmod/framebuf4.py
6 issues
Line: 5
Column: 5
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
def printbuf():
print("--8<--")
for y in range(h):
Reported by Pylint.
Line: 1
Column: 1
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
def printbuf():
print("--8<--")
Reported by Pylint.
Line: 8
Column: 1
raise SystemExit
def printbuf():
print("--8<--")
for y in range(h):
print(buf[y * w // 2 : (y + 1) * w // 2])
print("-->8--")
Reported by Pylint.
Line: 10
Column: 9
def printbuf():
print("--8<--")
for y in range(h):
print(buf[y * w // 2 : (y + 1) * w // 2])
print("-->8--")
w = 16
Reported by Pylint.
Line: 15
Column: 1
print("-->8--")
w = 16
h = 8
buf = bytearray(w * h // 2)
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB)
# fill
Reported by Pylint.
Line: 16
Column: 1
w = 16
h = 8
buf = bytearray(w * h // 2)
fbuf = framebuf.FrameBuffer(buf, w, h, framebuf.GS4_HMSB)
# fill
fbuf.fill(0x0F)
Reported by Pylint.
tests/extmod/framebuf1.py
6 issues
Line: 5
Column: 5
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
w = 5
h = 16
size = w * h // 8
buf = bytearray(size)
Reported by Pylint.
Line: 1
Column: 1
try:
import framebuf
except ImportError:
print("SKIP")
raise SystemExit
w = 5
h = 16
size = w * h // 8
Reported by Pylint.
Line: 7
Column: 1
print("SKIP")
raise SystemExit
w = 5
h = 16
size = w * h // 8
buf = bytearray(size)
maps = {
framebuf.MONO_VLSB: "MONO_VLSB",
Reported by Pylint.
Line: 8
Column: 1
raise SystemExit
w = 5
h = 16
size = w * h // 8
buf = bytearray(size)
maps = {
framebuf.MONO_VLSB: "MONO_VLSB",
framebuf.MONO_HLSB: "MONO_HLSB",
Reported by Pylint.
Line: 9
Column: 1
w = 5
h = 16
size = w * h // 8
buf = bytearray(size)
maps = {
framebuf.MONO_VLSB: "MONO_VLSB",
framebuf.MONO_HLSB: "MONO_HLSB",
framebuf.MONO_HMSB: "MONO_HMSB",
Reported by Pylint.
Line: 17
Column: 16
framebuf.MONO_HMSB: "MONO_HMSB",
}
for mapping in maps.keys():
for x in range(size):
buf[x] = 0
fbuf = framebuf.FrameBuffer(buf, w, h, mapping)
print(maps[mapping])
# access as buffer
Reported by Pylint.
tests/misc/sys_settrace_subdir/sys_settrace_importme.py
6 issues
Line: 4
Column: 9
print("Yep, I got imported.")
try:
x = const(1)
except NameError:
print("const not defined")
const = lambda x: x
Reported by Pylint.
Line: 1
Column: 1
print("Yep, I got imported.")
try:
x = const(1)
except NameError:
print("const not defined")
const = lambda x: x
Reported by Pylint.
Line: 13
Column: 1
_CNT01 = "CONST01"
_CNT02 = const(123)
A123 = const(123)
a123 = const(123)
def dummy():
return False
Reported by Pylint.
Line: 16
Column: 1
a123 = const(123)
def dummy():
return False
def saysomething():
print("There, I said it.")
Reported by Pylint.
Line: 20
Column: 1
return False
def saysomething():
print("There, I said it.")
def neverexecuted():
print("Never got here!")
Reported by Pylint.
Line: 24
Column: 1
print("There, I said it.")
def neverexecuted():
print("Never got here!")
print("Yep, got here")
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.
tests/basics/int_big_xor.py
6 issues
Line: 1
Column: 1
# test + +
print(0 ^ (1 << 80))
print((1 << 80) ^ (1 << 80))
print((1 << 80) ^ 0)
a = 0xfffffffffffffffffffffffffffff
print(a ^ (1 << 100))
print(a ^ (1 << 200))
Reported by Pylint.
Line: 1
Column: 11
# test + +
print(0 ^ (1 << 80))
print((1 << 80) ^ (1 << 80))
print((1 << 80) ^ 0)
a = 0xfffffffffffffffffffffffffffff
print(a ^ (1 << 100))
print(a ^ (1 << 200))
Reported by Pylint.
Line: 7
Column: 1
print((1 << 80) ^ (1 << 80))
print((1 << 80) ^ 0)
a = 0xfffffffffffffffffffffffffffff
print(a ^ (1 << 100))
print(a ^ (1 << 200))
print(a ^ a == 0)
print(bool(a ^ a))
Reported by Pylint.
Line: 13
Column: 11
print(a ^ a == 0)
print(bool(a ^ a))
# test - +
print((-1 << 80) ^ (1 << 80))
print((-1 << 80) ^ 0)
print((-a) ^ (1 << 100))
Reported by Pylint.
Line: 25
Column: 11
i = -1
print(i ^ 0xffffffffffffffff) # carry overflows to higher digit
# test + -
print(0 ^ (-1 << 80))
print((1 << 80) ^ (-1 << 80))
print(a ^ (-1 << 100))
Reported by Pylint.
Line: 35
Column: 11
print(a ^ (-a) == 0)
print(bool(a ^ (-a)))
# test - -
print((-1 << 80) ^ (-1 << 80))
print((-a) ^ (-1 << 100))
print((-a) ^ (-1 << 200))
Reported by Pylint.
tests/internal_bench/func_args-3.1-kw_1.py
6 issues
Line: 4
Column: 10
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 1
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 1
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 4
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 4
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 8
Column: 1
pass
def test(num):
for i in iter(range(num)):
func(a=i)
bench.run(test)
Reported by Pylint.
tests/internal_bench/func_args-1.1-pos_1.py
6 issues
Line: 4
Column: 10
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 1
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 1
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 4
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 4
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 8
Column: 1
pass
def test(num):
for i in iter(range(num)):
func(i)
bench.run(test)
Reported by Pylint.