The following issues were found
tools/tinytest-codegen.py
19 issues
Line: 3
Column: 1
#!/usr/bin/env python3
import os, sys
from glob import glob
from re import sub
import argparse
def escape(s):
Reported by Pylint.
Line: 52
Column: 4
testgroup_struct = "struct testgroup_t groups[] = {{\n{body}\n END_OF_GROUPS\n}};"
testgroup_member = ' {{ "{name}", {name}_tests }},'
## XXX: may be we could have `--without <groups>` argument...
# currently these tests are selected because they pass on qemu-arm
test_dirs = (
"basics",
"micropython",
"misc",
Reported by Pylint.
Line: 133
Column: 4
output.append(testgroup_struct.format(body="\n".join(testgroup_members)))
## XXX: may be we could have `--output <filename>` argument...
# Don't depend on what system locale is set, use utf8 encoding.
sys.stdout.buffer.write("\n\n".join(output).encode("utf8"))
Reported by Pylint.
Line: 1
Column: 1
#!/usr/bin/env python3
import os, sys
from glob import glob
from re import sub
import argparse
def escape(s):
Reported by Pylint.
Line: 1
Column: 1
#!/usr/bin/env python3
import os, sys
from glob import glob
from re import sub
import argparse
def escape(s):
Reported by Pylint.
Line: 3
Column: 1
#!/usr/bin/env python3
import os, sys
from glob import glob
from re import sub
import argparse
def escape(s):
Reported by Pylint.
Line: 9
Column: 1
import argparse
def escape(s):
s = s.decode()
lookup = {
"\0": "\\0",
"\t": "\\t",
"\n": '\\n"\n"',
Reported by Pylint.
Line: 9
Column: 1
import argparse
def escape(s):
s = s.decode()
lookup = {
"\0": "\\0",
"\t": "\\t",
"\n": '\\n"\n"',
Reported by Pylint.
Line: 22
Column: 1
return '""\n"{}"'.format("".join([lookup[x] if x in lookup else x for x in s]))
def chew_filename(t):
return {"func": "test_{}_fn".format(sub(r"/|\.|-", "_", t)), "desc": t}
def script_to_map(test_file):
r = {"name": chew_filename(test_file)["func"]}
Reported by Pylint.
Line: 22
Column: 1
return '""\n"{}"'.format("".join([lookup[x] if x in lookup else x for x in s]))
def chew_filename(t):
return {"func": "test_{}_fn".format(sub(r"/|\.|-", "_", t)), "desc": t}
def script_to_map(test_file):
r = {"name": chew_filename(test_file)["func"]}
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.
tests/extmod/vfs_blockdev.py
19 issues
Line: 6
Column: 5
try:
import uos
uos.VfsFat
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 7
Column: 5
import uos
uos.VfsFat
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 10
Column: 5
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 512
Reported by Pylint.
Line: 32
Column: 25
for i in range(len(buf)):
self.data[addr + i] = buf[i]
def ioctl(self, op, arg):
if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
if op == 5: # block size
return self.ERASE_BLOCK_SIZE
if op == 6: # erase block
Reported by Pylint.
Line: 41
Column: 10
return 0
def test(bdev, vfs_class):
print("test", vfs_class)
# mkfs
vfs_class.mkfs(bdev)
Reported by Pylint.
Line: 55
Column: 9
# open, write close
f = vfs.open("test", "w")
for i in range(10):
f.write("some data")
f.close()
# ilistdir
print(list(vfs.ilistdir()))
Reported by Pylint.
Line: 71
Column: 5
bdev = RAMBlockDevice(50)
except MemoryError:
print("SKIP")
raise SystemExit
test(bdev, uos.VfsFat)
test(bdev, uos.VfsLfs2)
Reported by Pylint.
Line: 1
Column: 1
# Test for behaviour of combined standard and extended block device
try:
import uos
uos.VfsFat
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 512
def __init__(self, blocks):
self.data = bytearray(blocks * self.ERASE_BLOCK_SIZE)
Reported by Pylint.
Line: 19
Column: 5
def __init__(self, blocks):
self.data = bytearray(blocks * self.ERASE_BLOCK_SIZE)
def readblocks(self, block, buf, off=0):
addr = block * self.ERASE_BLOCK_SIZE + off
for i in range(len(buf)):
buf[i] = self.data[addr + i]
def writeblocks(self, block, buf, off=None):
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/multi_net/uasyncio_tcp_readexactly.py
19 issues
Line: 44
Column: 5
ev = asyncio.Event()
server = await asyncio.start_server(handle_connection, "0.0.0.0", PORT)
print("server running")
multitest.next()
async with server:
await asyncio.wait_for(ev.wait(), 10)
async def tcp_client():
Reported by Pylint.
Line: 50
Column: 52
async def tcp_client():
reader, writer = await asyncio.open_connection(IP, PORT)
print(await reader.readexactly(2))
print(await reader.readexactly(0))
print(await reader.readexactly(1))
try:
print(await reader.readexactly(2))
Reported by Pylint.
Line: 62
Column: 5
def instance0():
multitest.globals(IP=multitest.get_network_ip())
asyncio.run(tcp_server())
def instance1():
multitest.next()
Reported by Pylint.
Line: 62
Column: 26
def instance0():
multitest.globals(IP=multitest.get_network_ip())
asyncio.run(tcp_server())
def instance1():
multitest.next()
Reported by Pylint.
Line: 67
Column: 5
def instance1():
multitest.next()
asyncio.run(tcp_client())
Reported by Pylint.
Line: 10
Column: 9
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
PORT = 8000
async def handle_connection(reader, writer):
Reported by Pylint.
Line: 15
Column: 29
PORT = 8000
async def handle_connection(reader, writer):
writer.write(b"a")
await writer.drain()
# Split the first 2 bytes up so the client must wait for the second one
await asyncio.sleep(0.1)
Reported by Pylint.
Line: 40
Column: 5
async def tcp_server():
global ev
ev = asyncio.Event()
server = await asyncio.start_server(handle_connection, "0.0.0.0", PORT)
print("server running")
multitest.next()
async with server:
Reported by Pylint.
Line: 42
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html
async def tcp_server():
global ev
ev = asyncio.Event()
server = await asyncio.start_server(handle_connection, "0.0.0.0", PORT)
print("server running")
multitest.next()
async with server:
await asyncio.wait_for(ev.wait(), 10)
Reported by Bandit.
Line: 50
Column: 13
async def tcp_client():
reader, writer = await asyncio.open_connection(IP, PORT)
print(await reader.readexactly(2))
print(await reader.readexactly(0))
print(await reader.readexactly(1))
try:
print(await reader.readexactly(2))
Reported by Pylint.
tests/micropython/native_try.py
19 issues
Line: 4
Column: 2
# test native try handling
# basic try-finally
@micropython.native
def f():
try:
fail
finally:
print("finally")
Reported by Pylint.
Line: 7
Column: 9
@micropython.native
def f():
try:
fail
finally:
print("finally")
try:
Reported by Pylint.
Line: 18
Column: 2
print("NameError")
# nested try-except with try-finally
@micropython.native
def f():
try:
try:
fail
finally:
Reported by Pylint.
Line: 19
Column: 1
# nested try-except with try-finally
@micropython.native
def f():
try:
try:
fail
finally:
print("finally")
Reported by Pylint.
Line: 32
Column: 2
f()
# check that locals written to in try blocks keep their values
@micropython.native
def f():
a = 100
try:
print(a)
a = 200
Reported by Pylint.
Line: 33
Column: 1
# check that locals written to in try blocks keep their values
@micropython.native
def f():
a = 100
try:
print(a)
a = 200
fail
Reported by Pylint.
Line: 7
Column: 9
@micropython.native
def f():
try:
fail
finally:
print("finally")
try:
Reported by Pylint.
Line: 22
Column: 13
def f():
try:
try:
fail
finally:
print("finally")
except NameError:
print("NameError")
Reported by Pylint.
Line: 38
Column: 9
try:
print(a)
a = 200
fail
except NameError:
print(a)
a = 300
print(a)
Reported by Pylint.
Line: 1
Column: 1
# test native try handling
# basic try-finally
@micropython.native
def f():
try:
fail
finally:
print("finally")
Reported by Pylint.
tests/basics/fun_varargs.py
19 issues
Line: 26
Column: 1
f3(1, 2, 3, 4)
# function with 1 default arg, then varargs
def f4(a=0, *args):
print(a, args)
f4()
f4(1)
f4(1, 2)
Reported by Pylint.
Line: 35
Column: 1
f4(1, 2, 3)
# function with 1 arg, 1 default arg, then varargs
def f5(a, b=0, *args):
print(a, b, args)
f5(1)
f5(1, 2)
f5(1, 2, 3)
Reported by Pylint.
Line: 1
Column: 1
# function with just varargs
def f1(*args):
print(args)
f1()
f1(1)
f1(1, 2)
# function with 1 arg, then varargs
Reported by Pylint.
Line: 2
Column: 1
# function with just varargs
def f1(*args):
print(args)
f1()
f1(1)
f1(1, 2)
# function with 1 arg, then varargs
Reported by Pylint.
Line: 2
Column: 1
# function with just varargs
def f1(*args):
print(args)
f1()
f1(1)
f1(1, 2)
# function with 1 arg, then varargs
Reported by Pylint.
Line: 10
Column: 1
f1(1, 2)
# function with 1 arg, then varargs
def f2(a, *args):
print(a, args)
f2(1)
f2(1, 2)
f2(1, 2, 3)
Reported by Pylint.
Line: 10
Column: 1
f1(1, 2)
# function with 1 arg, then varargs
def f2(a, *args):
print(a, args)
f2(1)
f2(1, 2)
f2(1, 2, 3)
Reported by Pylint.
Line: 10
Column: 1
f1(1, 2)
# function with 1 arg, then varargs
def f2(a, *args):
print(a, args)
f2(1)
f2(1, 2)
f2(1, 2, 3)
Reported by Pylint.
Line: 18
Column: 1
f2(1, 2, 3)
# function with 2 args, then varargs
def f3(a, b, *args):
print(a, b, args)
f3(1, 2)
f3(1, 2, 3)
f3(1, 2, 3, 4)
Reported by Pylint.
Line: 18
Column: 1
f2(1, 2, 3)
# function with 2 args, then varargs
def f3(a, b, *args):
print(a, b, args)
f3(1, 2)
f3(1, 2, 3)
f3(1, 2, 3, 4)
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.
tests/basics/special_methods2.py
19 issues
Line: 41
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: 107
Column: 5
+cud1
except TypeError:
print("SKIP")
raise SystemExit
# the following require MICROPY_PY_ALL_SPECIAL_METHODS
+cud1
-cud1
~cud1
Reported by Pylint.
Line: 110
Column: 1
raise SystemExit
# the following require MICROPY_PY_ALL_SPECIAL_METHODS
+cud1
-cud1
~cud1
cud1 * cud2
cud1 @ cud2
cud1 / cud2
Reported by Pylint.
Line: 111
Column: 1
# the following require MICROPY_PY_ALL_SPECIAL_METHODS
+cud1
-cud1
~cud1
cud1 * cud2
cud1 @ cud2
cud1 / cud2
cud2 // cud1
Reported by Pylint.
Line: 112
Column: 1
# the following require MICROPY_PY_ALL_SPECIAL_METHODS
+cud1
-cud1
~cud1
cud1 * cud2
cud1 @ cud2
cud1 / cud2
cud2 // cud1
cud1 += cud2
Reported by Pylint.
Line: 113
Column: 1
+cud1
-cud1
~cud1
cud1 * cud2
cud1 @ cud2
cud1 / cud2
cud2 // cud1
cud1 += cud2
cud1 -= cud2
Reported by Pylint.
Line: 114
Column: 1
-cud1
~cud1
cud1 * cud2
cud1 @ cud2
cud1 / cud2
cud2 // cud1
cud1 += cud2
cud1 -= cud2
cud1 % 2
Reported by Pylint.
Line: 115
Column: 1
~cud1
cud1 * cud2
cud1 @ cud2
cud1 / cud2
cud2 // cud1
cud1 += cud2
cud1 -= cud2
cud1 % 2
cud1 ** 2
Reported by Pylint.
Line: 116
Column: 1
cud1 * cud2
cud1 @ cud2
cud1 / cud2
cud2 // cud1
cud1 += cud2
cud1 -= cud2
cud1 % 2
cud1 ** 2
cud1 | cud2
Reported by Pylint.
Line: 119
Column: 1
cud2 // cud1
cud1 += cud2
cud1 -= cud2
cud1 % 2
cud1 ** 2
cud1 | cud2
cud1 & cud2
cud1 ^ cud2
cud1 << 1
Reported by Pylint.
tests/extmod/vfs_fat_mtime.py
19 issues
Line: 6
Column: 5
try:
import utime, uos
utime.time
utime.sleep
uos.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 7
Column: 5
import utime, uos
utime.time
utime.sleep
uos.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 8
Column: 5
utime.time
utime.sleep
uos.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 11
Column: 5
uos.VfsFat
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 512
Reported by Pylint.
Line: 30
Column: 25
for i in range(len(buf)):
self.data[addr + i] = buf[i]
def ioctl(self, op, arg):
if op == 4: # block count
return len(self.data) // self.ERASE_BLOCK_SIZE
if op == 5: # block size
return self.ERASE_BLOCK_SIZE
Reported by Pylint.
Line: 37
Column: 10
return self.ERASE_BLOCK_SIZE
def test(bdev, vfs_class):
print("test", vfs_class)
# Initial format of block device.
vfs_class.mkfs(bdev)
Reported by Pylint.
Line: 47
Column: 5
vfs = vfs_class(bdev)
# Create an empty file, should have a timestamp.
current_time = int(utime.time())
vfs.open("test1", "wt").close()
# Wait 2 seconds so mtime will increase (FAT has 2 second resolution).
utime.sleep(2)
Reported by Pylint.
Line: 62
Column: 3
print(stat1[8] != 0, stat2[8] != 0)
# Check that test1 has mtime which matches time.time() at point of creation.
# TODO this currently fails on the unix port because FAT stores timestamps
# in localtime and stat() is UTC based.
# print(current_time - 1 <= stat1[8] <= current_time + 1)
# Check that test1 is older than test2.
print(stat1[8] < stat2[8])
Reported by Pylint.
Line: 1
Column: 1
# Test for VfsFat using a RAM device, mtime feature
try:
import utime, uos
utime.time
utime.sleep
uos.VfsFat
except (ImportError, AttributeError):
Reported by Pylint.
Line: 4
Column: 5
# Test for VfsFat using a RAM device, mtime feature
try:
import utime, uos
utime.time
utime.sleep
uos.VfsFat
except (ImportError, AttributeError):
Reported by Pylint.