The following issues were found
tests/basics/special_methods.py
20 issues
Line: 40
Column: 5
def __floordiv__(self, other):
print("__floordiv__ called")
def __index__(self, other):
print("__index__ called")
def __inv__(self):
print("__inv__ called")
Reported by Pylint.
Line: 103
Column: 1
cud2 = Cud()
str(cud1)
cud1 == cud1
cud1 == cud2
cud1 != cud1
cud1 != cud2
cud1 < cud2
cud1 <= cud2
Reported by Pylint.
Line: 104
Column: 1
str(cud1)
cud1 == cud1
cud1 == cud2
cud1 != cud1
cud1 != cud2
cud1 < cud2
cud1 <= cud2
cud1 == cud2
Reported by Pylint.
Line: 105
Column: 1
str(cud1)
cud1 == cud1
cud1 == cud2
cud1 != cud1
cud1 != cud2
cud1 < cud2
cud1 <= cud2
cud1 == cud2
cud1 >= cud2
Reported by Pylint.
Line: 106
Column: 1
cud1 == cud1
cud1 == cud2
cud1 != cud1
cud1 != cud2
cud1 < cud2
cud1 <= cud2
cud1 == cud2
cud1 >= cud2
cud1 > cud2
Reported by Pylint.
Line: 107
Column: 1
cud1 == cud2
cud1 != cud1
cud1 != cud2
cud1 < cud2
cud1 <= cud2
cud1 == cud2
cud1 >= cud2
cud1 > cud2
cud1 + cud2
Reported by Pylint.
Line: 108
Column: 1
cud1 != cud1
cud1 != cud2
cud1 < cud2
cud1 <= cud2
cud1 == cud2
cud1 >= cud2
cud1 > cud2
cud1 + cud2
cud1 - cud2
Reported by Pylint.
Line: 109
Column: 1
cud1 != cud2
cud1 < cud2
cud1 <= cud2
cud1 == cud2
cud1 >= cud2
cud1 > cud2
cud1 + cud2
cud1 - cud2
print(int(cud1))
Reported by Pylint.
Line: 110
Column: 1
cud1 < cud2
cud1 <= cud2
cud1 == cud2
cud1 >= cud2
cud1 > cud2
cud1 + cud2
cud1 - cud2
print(int(cud1))
Reported by Pylint.
Line: 111
Column: 1
cud1 <= cud2
cud1 == cud2
cud1 >= cud2
cud1 > cud2
cud1 + cud2
cud1 - cud2
print(int(cud1))
class BadInt:
Reported by Pylint.
tests/basics/scope_implicit.py
20 issues
Line: 12
Column: 1
print(f()())
# implicit nonlocal at inner level, with variable defined after closure
def f():
def g():
def h():
return x # implicit nonlocal
return h
x = 4 # variable defined after function that closes over it
Reported by Pylint.
Line: 22
Column: 1
print(f()()())
# local variable which should not be implicitly made nonlocal
def f():
x = 0
def g():
x # local because next statement assigns to it
x = 1
g()
Reported by Pylint.
Line: 25
Column: 9
def f():
x = 0
def g():
x # local because next statement assigns to it
x = 1
g()
try:
f()
except NameError:
Reported by Pylint.
Line: 23
Column: 5
# local variable which should not be implicitly made nonlocal
def f():
x = 0
def g():
x # local because next statement assigns to it
x = 1
g()
try:
Reported by Pylint.
Line: 25
Column: 9
def f():
x = 0
def g():
x # local because next statement assigns to it
x = 1
g()
try:
f()
except NameError:
Reported by Pylint.
Line: 1
Column: 1
# test implicit scoping rules
# implicit nonlocal, with variable defined after closure
def f():
def g():
return x # implicit nonlocal
x = 3 # variable defined after function that closes over it
return g
print(f()())
Reported by Pylint.
Line: 4
Column: 1
# test implicit scoping rules
# implicit nonlocal, with variable defined after closure
def f():
def g():
return x # implicit nonlocal
x = 3 # variable defined after function that closes over it
return g
print(f()())
Reported by Pylint.
Line: 4
Column: 1
# test implicit scoping rules
# implicit nonlocal, with variable defined after closure
def f():
def g():
return x # implicit nonlocal
x = 3 # variable defined after function that closes over it
return g
print(f()())
Reported by Pylint.
Line: 5
Column: 5
# implicit nonlocal, with variable defined after closure
def f():
def g():
return x # implicit nonlocal
x = 3 # variable defined after function that closes over it
return g
print(f()())
Reported by Pylint.
Line: 7
Column: 5
def f():
def g():
return x # implicit nonlocal
x = 3 # variable defined after function that closes over it
return g
print(f()())
# implicit nonlocal at inner level, with variable defined after closure
def f():
Reported by Pylint.
tests/basics/try_finally_return.py
20 issues
Line: 35
Column: 1
print(f())
# multiple for loops within try-finally
def f():
try:
for i in [1, 2]:
for j in [3, 4]:
return (i, j)
finally:
Reported by Pylint.
Line: 45
Column: 1
print(f())
# multiple for loops and nested try-finally's
def f():
try:
for i in [1, 2]:
for j in [3, 4]:
try:
for k in [5, 6]:
Reported by Pylint.
Line: 60
Column: 1
print(f())
# multiple for loops that are optimised, and nested try-finally's
def f():
try:
for i in range(1, 3):
for j in range(3, 5):
try:
for k in range(5, 7):
Reported by Pylint.
Line: 1
Column: 1
def func1():
try:
return "it worked"
finally:
print("finally 1")
print(func1())
Reported by Pylint.
Line: 1
Column: 1
def func1():
try:
return "it worked"
finally:
print("finally 1")
print(func1())
Reported by Pylint.
Line: 10
Column: 1
print(func1())
def func2():
try:
return "it worked"
finally:
print("finally 2")
Reported by Pylint.
Line: 16
Column: 1
finally:
print("finally 2")
def func3():
try:
s = func2()
return s + ", did this work?"
finally:
print("finally 3")
Reported by Pylint.
Line: 18
Column: 9
def func3():
try:
s = func2()
return s + ", did this work?"
finally:
print("finally 3")
print(func3())
Reported by Pylint.
Line: 26
Column: 1
print(func3())
# for loop within try-finally
def f():
try:
for i in [1, 2]:
return i
finally:
print('finally')
Reported by Pylint.
Line: 26
Column: 1
print(func3())
# for loop within try-finally
def f():
try:
for i in [1, 2]:
return i
finally:
print('finally')
Reported by Pylint.
tests/basics/boundmeth1.py
20 issues
Line: 1
Column: 1
# tests basics of bound methods
# uPy and CPython differ when printing a bound method, so just print the type
print(type(repr([].append)))
class A:
def f(self):
return 0
def g(self, a):
Reported by Pylint.
Line: 6
Column: 1
# uPy and CPython differ when printing a bound method, so just print the type
print(type(repr([].append)))
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
Reported by Pylint.
Line: 6
Column: 1
# uPy and CPython differ when printing a bound method, so just print the type
print(type(repr([].append)))
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
Reported by Pylint.
Line: 7
Column: 5
print(type(repr([].append)))
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
Reported by Pylint.
Line: 7
Column: 5
print(type(repr([].append)))
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
Reported by Pylint.
Line: 7
Column: 5
print(type(repr([].append)))
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
Reported by Pylint.
Line: 9
Column: 5
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
# bound method with no extra args
Reported by Pylint.
Line: 9
Column: 5
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
# bound method with no extra args
Reported by Pylint.
Line: 9
Column: 5
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
# bound method with no extra args
Reported by Pylint.
Line: 9
Column: 5
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
# bound method with no extra args
Reported by Pylint.
tests/basics/unary_op.py
20 issues
Line: 34
Column: 7
class D(type): pass
d = D("foo", (), {})
print(not d)
print(True if d else False)
Reported by Pylint.
Line: 1
Column: 1
x = 1
print(+x)
print(-x)
print(~x)
print(not None)
print(not False)
print(not True)
print(not 0)
Reported by Pylint.
Line: 1
Column: 1
x = 1
print(+x)
print(-x)
print(~x)
print(not None)
print(not False)
print(not True)
print(not 0)
Reported by Pylint.
Line: 20
Column: 1
print(not {1:1})
# check user instance
class A: pass
print(not A())
# check user instances derived from builtins
class B(int): pass
print(not B())
Reported by Pylint.
Line: 20
Column: 1
print(not {1:1})
# check user instance
class A: pass
print(not A())
# check user instances derived from builtins
class B(int): pass
print(not B())
Reported by Pylint.
Line: 20
Column: 10
print(not {1:1})
# check user instance
class A: pass
print(not A())
# check user instances derived from builtins
class B(int): pass
print(not B())
Reported by Pylint.
Line: 20
Column: 1
print(not {1:1})
# check user instance
class A: pass
print(not A())
# check user instances derived from builtins
class B(int): pass
print(not B())
Reported by Pylint.
Line: 24
Column: 1
print(not A())
# check user instances derived from builtins
class B(int): pass
print(not B())
print(True if B() else False)
class C(list): pass
print(not C())
print(True if C() else False)
Reported by Pylint.
Line: 24
Column: 15
print(not A())
# check user instances derived from builtins
class B(int): pass
print(not B())
print(True if B() else False)
class C(list): pass
print(not C())
print(True if C() else False)
Reported by Pylint.
Line: 24
Column: 1
print(not A())
# check user instances derived from builtins
class B(int): pass
print(not B())
print(True if B() else False)
class C(list): pass
print(not C())
print(True if C() else False)
Reported by Pylint.
tests/micropython/viper_binop_divmod.py
19 issues
Line: 4
Column: 2
# test floor-division and modulo operators
@micropython.viper
def div(x: int, y: int) -> int:
return x // y
@micropython.viper
Reported by Pylint.
Line: 9
Column: 2
return x // y
@micropython.viper
def mod(x: int, y: int) -> int:
return x % y
def dm(x, y):
Reported by Pylint.
Line: 5
Column: 17
@micropython.viper
def div(x: int, y: int) -> int:
return x // y
@micropython.viper
def mod(x: int, y: int) -> int:
Reported by Pylint.
Line: 5
Column: 9
@micropython.viper
def div(x: int, y: int) -> int:
return x // y
@micropython.viper
def mod(x: int, y: int) -> int:
Reported by Pylint.
Line: 10
Column: 17
@micropython.viper
def mod(x: int, y: int) -> int:
return x % y
def dm(x, y):
print(div(x, y), mod(x, y))
Reported by Pylint.
Line: 10
Column: 9
@micropython.viper
def mod(x: int, y: int) -> int:
return x % y
def dm(x, y):
print(div(x, y), mod(x, y))
Reported by Pylint.
Line: 14
Column: 8
return x % y
def dm(x, y):
print(div(x, y), mod(x, y))
for x in (-6, 6):
for y in range(-7, 8):
Reported by Pylint.
Line: 14
Column: 11
return x % y
def dm(x, y):
print(div(x, y), mod(x, y))
for x in (-6, 6):
for y in range(-7, 8):
Reported by Pylint.
Line: 1
Column: 1
# test floor-division and modulo operators
@micropython.viper
def div(x: int, y: int) -> int:
return x // y
@micropython.viper
Reported by Pylint.
Line: 5
Column: 1
@micropython.viper
def div(x: int, y: int) -> int:
return x // y
@micropython.viper
def mod(x: int, y: int) -> int:
Reported by Pylint.
tests/micropython/import_mpy_invalid.py
19 issues
Line: 6
Column: 5
try:
import usys, uio, uos
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 7
Column: 5
import usys, uio, uos
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 10
Column: 5
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class UserFile(uio.IOBase):
def __init__(self, data):
self.data = memoryview(data)
Reported by Pylint.
Line: 24
Column: 21
self.pos += n
return n
def ioctl(self, req, arg):
return 0
class UserFS:
def __init__(self, files):
Reported by Pylint.
Line: 24
Column: 26
self.pos += n
return n
def ioctl(self, req, arg):
return 0
class UserFS:
def __init__(self, files):
Reported by Pylint.
Line: 43
Column: 26
return (32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
raise OSError
def open(self, path, mode):
return UserFile(self.files[path])
# these are the test .mpy files
user_files = {
Reported by Pylint.
Line: 1
Column: 1
# test importing of invalid .mpy files
try:
import usys, uio, uos
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
Reported by Pylint.
Line: 4
Column: 5
# test importing of invalid .mpy files
try:
import usys, uio, uos
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
class UserFile(uio.IOBase):
def __init__(self, data):
self.data = memoryview(data)
self.pos = 0
def readinto(self, buf):
Reported by Pylint.
Line: 18
Column: 5
self.data = memoryview(data)
self.pos = 0
def readinto(self, buf):
n = min(len(buf), len(self.data) - self.pos)
buf[:n] = self.data[self.pos : self.pos + n]
self.pos += n
return n
Reported by Pylint.
tests/micropython/import_mpy_native_x64.py
19 issues
Line: 6
Column: 5
try:
import usys, uio, uos
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 7
Column: 5
import usys, uio, uos
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
if not (usys.platform == "linux" and usys.maxsize > 2 ** 32):
Reported by Pylint.
Line: 10
Column: 5
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
if not (usys.platform == "linux" and usys.maxsize > 2 ** 32):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 28
Column: 26
self.pos += n
return n
def ioctl(self, req, arg):
return 0
class UserFS:
def __init__(self, files):
Reported by Pylint.
Line: 28
Column: 21
self.pos += n
return n
def ioctl(self, req, arg):
return 0
class UserFS:
def __init__(self, files):
Reported by Pylint.
Line: 47
Column: 26
return (32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
raise OSError
def open(self, path, mode):
return UserFile(self.files[path])
# these are the test .mpy files
# fmt: off
Reported by Pylint.
Line: 1
Column: 1
# test importing of .mpy files with native code (x64 only)
try:
import usys, uio, uos
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
Reported by Pylint.
Line: 4
Column: 5
# test importing of .mpy files with native code (x64 only)
try:
import usys, uio, uos
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
Reported by Pylint.
Line: 17
Column: 1
raise SystemExit
class UserFile(uio.IOBase):
def __init__(self, data):
self.data = memoryview(data)
self.pos = 0
def readinto(self, buf):
Reported by Pylint.
Line: 22
Column: 5
self.data = memoryview(data)
self.pos = 0
def readinto(self, buf):
n = min(len(buf), len(self.data) - self.pos)
buf[:n] = self.data[self.pos : self.pos + n]
self.pos += n
return n
Reported by Pylint.
drivers/sdcard/sdtest.py
19 issues
Line: 3
Column: 1
# Test for sdcard block protocol
# Peter hinch 30th Jan 2016
import os, sdcard, machine
def sdtest():
spi = machine.SPI(1)
spi.init() # Ensure right baudrate
sd = sdcard.SDCard(spi, machine.Pin.board.X21) # Compatible with PCB
Reported by Pylint.
Line: 10
Column: 11
spi = machine.SPI(1)
spi.init() # Ensure right baudrate
sd = sdcard.SDCard(spi, machine.Pin.board.X21) # Compatible with PCB
vfs = os.VfsFat(sd)
os.mount(vfs, "/fc")
print("Filesystem check")
print(os.listdir("/fc"))
line = "abcdefghijklmnopqrstuvwxyz\n"
Reported by Pylint.
Line: 11
Column: 5
spi.init() # Ensure right baudrate
sd = sdcard.SDCard(spi, machine.Pin.board.X21) # Compatible with PCB
vfs = os.VfsFat(sd)
os.mount(vfs, "/fc")
print("Filesystem check")
print(os.listdir("/fc"))
line = "abcdefghijklmnopqrstuvwxyz\n"
lines = line * 200 # 5400 chars
Reported by Pylint.
Line: 45
Column: 5
result2 = f.read()
print(len(result2), "bytes read")
os.umount("/fc")
print()
print("Verifying data read back")
success = True
if result1 == "".join((lines, short, lines)):
Reported by Pylint.
Line: 1
Column: 1
# Test for sdcard block protocol
# Peter hinch 30th Jan 2016
import os, sdcard, machine
def sdtest():
spi = machine.SPI(1)
spi.init() # Ensure right baudrate
sd = sdcard.SDCard(spi, machine.Pin.board.X21) # Compatible with PCB
Reported by Pylint.
Line: 3
Column: 1
# Test for sdcard block protocol
# Peter hinch 30th Jan 2016
import os, sdcard, machine
def sdtest():
spi = machine.SPI(1)
spi.init() # Ensure right baudrate
sd = sdcard.SDCard(spi, machine.Pin.board.X21) # Compatible with PCB
Reported by Pylint.
Line: 3
Column: 1
# Test for sdcard block protocol
# Peter hinch 30th Jan 2016
import os, sdcard, machine
def sdtest():
spi = machine.SPI(1)
spi.init() # Ensure right baudrate
sd = sdcard.SDCard(spi, machine.Pin.board.X21) # Compatible with PCB
Reported by Pylint.
Line: 6
Column: 1
import os, sdcard, machine
def sdtest():
spi = machine.SPI(1)
spi.init() # Ensure right baudrate
sd = sdcard.SDCard(spi, machine.Pin.board.X21) # Compatible with PCB
vfs = os.VfsFat(sd)
os.mount(vfs, "/fc")
Reported by Pylint.
Line: 9
Column: 5
def sdtest():
spi = machine.SPI(1)
spi.init() # Ensure right baudrate
sd = sdcard.SDCard(spi, machine.Pin.board.X21) # Compatible with PCB
vfs = os.VfsFat(sd)
os.mount(vfs, "/fc")
print("Filesystem check")
print(os.listdir("/fc"))
Reported by Pylint.
Line: 19
Column: 5
lines = line * 200 # 5400 chars
short = "1234567890\n"
fn = "/fc/rats.txt"
print()
print("Multiple block read/write")
with open(fn, "w") as f:
n = f.write(lines)
print(n, "bytes written")
Reported by Pylint.
tests/multi_net/tcp_client_rst.py
19 issues
Line: 15
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
# 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: 20
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()
s2, _ = s.accept()
s2.setblocking(False)
poll = select.poll()
poll.register(s2, select.POLLIN)
time.sleep(0.4)
Reported by Pylint.
Line: 47
Column: 9
# Client
def instance1():
if not hasattr(socket, "SO_LINGER"):
multitest.skip()
multitest.next()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.connect(socket.getaddrinfo(IP, PORT)[0][-1])
lgr_onoff = 1
lgr_linger = 0
Reported by Pylint.
Line: 48
Column: 5
def instance1():
if not hasattr(socket, "SO_LINGER"):
multitest.skip()
multitest.next()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.connect(socket.getaddrinfo(IP, PORT)[0][-1])
lgr_onoff = 1
lgr_linger = 0
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", lgr_onoff, lgr_linger))
Reported by Pylint.
Line: 50
Column: 34
multitest.skip()
multitest.next()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.connect(socket.getaddrinfo(IP, PORT)[0][-1])
lgr_onoff = 1
lgr_linger = 0
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", lgr_onoff, lgr_linger))
s.send(b"GET / HTTP/1.0\r\n\r\n")
time.sleep(0.2)
Reported by Pylint.
Line: 18
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()
s2, _ = s.accept()
s2.setblocking(False)
poll = select.poll()
Reported by Bandit.
Line: 27
Column: 3
poll.register(s2, select.POLLIN)
time.sleep(0.4)
print(convert_poll_list(poll.poll(1000)))
# TODO: the following recv don't work with lwip, it abandons data upon TCP RST
try:
print(s2.recv(10))
print(convert_poll_list(poll.poll(1000)))
print(s2.recv(10))
print(convert_poll_list(poll.poll(1000)))
Reported by Pylint.
Line: 38
Column: 3
except OSError as er:
print(er.errno)
print(convert_poll_list(poll.poll(1000)))
# TODO lwip raises here but apparently it shouldn't
print(s2.recv(10))
print(convert_poll_list(poll.poll(1000)))
s.close()
Reported by Pylint.
Line: 1
Column: 1
# Test when client does a TCP RST on an open connection
import struct, time, socket, select
PORT = 8000
def convert_poll_list(l):
# To be compatible across all ports/targets
Reported by Pylint.