The following issues were found
ports/esp8266/modules/_boot.py
8 issues
Line: 3
Column: 1
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
if bdev:
try:
uos.mount(bdev, "/")
Reported by Pylint.
Line: 3
Column: 15
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
if bdev:
try:
uos.mount(bdev, "/")
Reported by Pylint.
Line: 3
Column: 31
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
if bdev:
try:
uos.mount(bdev, "/")
Reported by Pylint.
Line: 4
Column: 1
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
if bdev:
try:
uos.mount(bdev, "/")
Reported by Pylint.
Line: 10
Column: 5
if bdev:
try:
uos.mount(bdev, "/")
except:
import inisetup
inisetup.setup()
gc.collect()
Reported by Pylint.
Line: 1
Column: 1
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
if bdev:
try:
uos.mount(bdev, "/")
Reported by Pylint.
Line: 4
Column: 1
import gc
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
if bdev:
try:
uos.mount(bdev, "/")
Reported by Pylint.
Line: 5
Column: 1
gc.threshold((gc.mem_free() + gc.mem_alloc()) // 4)
import uos
from flashbdev import bdev
if bdev:
try:
uos.mount(bdev, "/")
except:
Reported by Pylint.
tests/extmod/uasyncio_cancel_fair2.py
8 issues
Line: 11
Column: 9
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task_a():
try:
while True:
Reported by Pylint.
Line: 23
Column: 18
print("cancelled a")
async def task_b(id, other):
while other.cancel():
print("sleep b", id)
await asyncio.sleep(0)
print("done b", id)
Reported by Pylint.
Line: 1
Column: 1
# Test fairness of cancelling a task
# That tasks which keeps being cancelled by multiple other tasks gets a chance to run
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
Reported by Pylint.
Line: 14
Column: 1
raise SystemExit
async def task_a():
try:
while True:
print("sleep a")
await asyncio.sleep(0)
except asyncio.CancelledError:
Reported by Pylint.
Line: 23
Column: 1
print("cancelled a")
async def task_b(id, other):
while other.cancel():
print("sleep b", id)
await asyncio.sleep(0)
print("done b", id)
Reported by Pylint.
Line: 23
Column: 1
print("cancelled a")
async def task_b(id, other):
while other.cancel():
print("sleep b", id)
await asyncio.sleep(0)
print("done b", id)
Reported by Pylint.
Line: 30
Column: 1
print("done b", id)
async def main():
t = asyncio.create_task(task_a())
for i in range(3):
asyncio.create_task(task_b(i, t))
await t
Reported by Pylint.
Line: 31
Column: 5
async def main():
t = asyncio.create_task(task_a())
for i in range(3):
asyncio.create_task(task_b(i, t))
await t
Reported by Pylint.
tests/basics/struct_micropython.py
8 issues
Line: 4
Column: 5
# test MicroPython-specific features of struct
try:
import ustruct as struct
except:
try:
import struct
except ImportError:
print("SKIP")
Reported by Pylint.
Line: 5
Column: 1
try:
import ustruct as struct
except:
try:
import struct
except ImportError:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 10
Column: 9
import struct
except ImportError:
print("SKIP")
raise SystemExit
class A():
pass
# pack and unpack objects
Reported by Pylint.
Line: 1
Column: 1
# test MicroPython-specific features of struct
try:
import ustruct as struct
except:
try:
import struct
except ImportError:
print("SKIP")
Reported by Pylint.
Line: 12
Column: 1
print("SKIP")
raise SystemExit
class A():
pass
# pack and unpack objects
o = A()
s = struct.pack("<O", o)
Reported by Pylint.
Line: 12
Column: 1
print("SKIP")
raise SystemExit
class A():
pass
# pack and unpack objects
o = A()
s = struct.pack("<O", o)
Reported by Pylint.
Line: 12
Column: 1
print("SKIP")
raise SystemExit
class A():
pass
# pack and unpack objects
o = A()
s = struct.pack("<O", o)
Reported by Pylint.
Line: 33
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
o = uctypes.addressof('abc')
s = struct.pack("<S", o)
o2 = struct.unpack("<S", s)
assert o2[0] == 'abc'
except ImportError:
pass
Reported by Bandit.
tests/basics/async_for2.py
8 issues
Line: 1
Column: 1
# test waiting within "async for" __anext__ function
try:
import usys as sys
except ImportError:
import sys
if sys.implementation.name == 'micropython':
# uPy allows normal generators to be awaitables
coroutine = lambda f: f
Reported by Pylint.
Line: 15
Column: 1
coroutine = types.coroutine
@coroutine
def f(x):
print('f start:', x)
yield x + 1
yield x + 2
return x + 3
Reported by Pylint.
Line: 15
Column: 1
coroutine = types.coroutine
@coroutine
def f(x):
print('f start:', x)
yield x + 1
yield x + 2
return x + 3
Reported by Pylint.
Line: 15
Column: 1
coroutine = types.coroutine
@coroutine
def f(x):
print('f start:', x)
yield x + 1
yield x + 2
return x + 3
Reported by Pylint.
Line: 21
Column: 1
yield x + 2
return x + 3
class ARange:
def __init__(self, high):
print('init')
self.cur = 0
self.high = high
Reported by Pylint.
Line: 34
Column: 9
async def __anext__(self):
print('anext')
print('f returned:', await f(20))
if self.cur < self.high:
val = self.cur
self.cur += 1
return val
else:
raise StopAsyncIteration
Reported by Pylint.
Line: 41
Column: 1
else:
raise StopAsyncIteration
async def coro():
async for x in ARange(4):
print('x', x)
o = coro()
try:
Reported by Pylint.
Line: 42
Column: 15
raise StopAsyncIteration
async def coro():
async for x in ARange(4):
print('x', x)
o = coro()
try:
while True:
Reported by Pylint.
tests/micropython/native_gen.py
8 issues
Line: 4
Column: 2
# test for native generators
# simple generator with yield and return
@micropython.native
def gen1(x):
yield x
yield x + 1
return x + 2
Reported by Pylint.
Line: 20
Column: 2
print(e.args[0])
# using yield from
@micropython.native
def gen2(x):
yield from range(x)
print(list(gen2(3)))
Reported by Pylint.
Line: 1
Column: 1
# test for native generators
# simple generator with yield and return
@micropython.native
def gen1(x):
yield x
yield x + 1
return x + 2
Reported by Pylint.
Line: 5
Column: 1
# simple generator with yield and return
@micropython.native
def gen1(x):
yield x
yield x + 1
return x + 2
Reported by Pylint.
Line: 5
Column: 1
# simple generator with yield and return
@micropython.native
def gen1(x):
yield x
yield x + 1
return x + 2
Reported by Pylint.
Line: 16
Column: 1
print(next(g))
try:
next(g)
except StopIteration as e:
print(e.args[0])
# using yield from
@micropython.native
def gen2(x):
Reported by Pylint.
Line: 21
Column: 1
# using yield from
@micropython.native
def gen2(x):
yield from range(x)
print(list(gen2(3)))
Reported by Pylint.
Line: 21
Column: 1
# using yield from
@micropython.native
def gen2(x):
yield from range(x)
print(list(gen2(3)))
Reported by Pylint.
tests/basics/assign1.py
8 issues
Line: 1
Column: 1
# test assignments
a = 1
print(a)
a = b = 2
print(a, b)
a = b = c = 3
Reported by Pylint.
Line: 3
Column: 1
# test assignments
a = 1
print(a)
a = b = 2
print(a, b)
a = b = c = 3
Reported by Pylint.
Line: 6
Column: 5
a = 1
print(a)
a = b = 2
print(a, b)
a = b = c = 3
print(a, b, c)
Reported by Pylint.
Line: 6
Column: 1
a = 1
print(a)
a = b = 2
print(a, b)
a = b = c = 3
print(a, b, c)
Reported by Pylint.
Line: 9
Column: 5
a = b = 2
print(a, b)
a = b = c = 3
print(a, b, c)
Reported by Pylint.
Line: 9
Column: 9
a = b = 2
print(a, b)
a = b = c = 3
print(a, b, c)
Reported by Pylint.
Line: 9
Column: 1
a = b = 2
print(a, b)
a = b = c = 3
print(a, b, c)
Reported by Pylint.
Line: 11
Column: 1
a = b = c = 3
print(a, b, c)
Reported by Pylint.
tests/basics/fun_defargs2.py
8 issues
Line: 1
Column: 1
# overriding default arguments
def foo(a, b=3):
print(a, b)
# override with positional
foo(1, 333)
# override with keyword
Reported by Pylint.
Line: 3
Column: 1
# overriding default arguments
def foo(a, b=3):
print(a, b)
# override with positional
foo(1, 333)
# override with keyword
Reported by Pylint.
Line: 3
Column: 1
# overriding default arguments
def foo(a, b=3):
print(a, b)
# override with positional
foo(1, 333)
# override with keyword
Reported by Pylint.
Line: 3
Column: 1
# overriding default arguments
def foo(a, b=3):
print(a, b)
# override with positional
foo(1, 333)
# override with keyword
Reported by Pylint.
Line: 3
Column: 1
# overriding default arguments
def foo(a, b=3):
print(a, b)
# override with positional
foo(1, 333)
# override with keyword
Reported by Pylint.
Line: 15
Column: 1
# override with keyword
foo(a=2, b=333)
def foo2(a=1, b=2):
print(a, b)
# default and keyword
foo2(b='two')
Reported by Pylint.
Line: 15
Column: 1
# override with keyword
foo(a=2, b=333)
def foo2(a=1, b=2):
print(a, b)
# default and keyword
foo2(b='two')
Reported by Pylint.
Line: 15
Column: 1
# override with keyword
foo(a=2, b=333)
def foo2(a=1, b=2):
print(a, b)
# default and keyword
foo2(b='two')
Reported by Pylint.
tests/basics/annotate_var.py
8 issues
Line: 22
Column: 1
f()
# here, "x" should remain a global
def f():
x.y: int
print(x)
f()
Reported by Pylint.
Line: 14
Column: 5
# a pure annotation in a function makes that variable local
def f():
x: int
try:
print(x)
except NameError:
print("NameError")
f()
Reported by Pylint.
Line: 1
Column: 1
# test PEP 526, varible annotations
x: int
print("x" in globals())
x: int = 1
print(x)
t: tuple = 1, 2
Reported by Pylint.
Line: 13
Column: 1
print(t)
# a pure annotation in a function makes that variable local
def f():
x: int
try:
print(x)
except NameError:
print("NameError")
Reported by Pylint.
Line: 13
Column: 1
print(t)
# a pure annotation in a function makes that variable local
def f():
x: int
try:
print(x)
except NameError:
print("NameError")
Reported by Pylint.
Line: 14
Column: 5
# a pure annotation in a function makes that variable local
def f():
x: int
try:
print(x)
except NameError:
print("NameError")
f()
Reported by Pylint.
Line: 22
Column: 1
f()
# here, "x" should remain a global
def f():
x.y: int
print(x)
f()
Reported by Pylint.
Line: 22
Column: 1
f()
# here, "x" should remain a global
def f():
x.y: int
print(x)
f()
Reported by Pylint.
examples/network/http_server.py
8 issues
Line: 3
Column: 1
try:
import usocket as socket
except:
import socket
CONTENT = b"""\
HTTP/1.0 200 OK
Reported by Pylint.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html
s = socket.socket()
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8080)
print("Bind address info:", ai)
addr = ai[0][-1]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
Reported by Bandit.
Line: 1
Column: 1
try:
import usocket as socket
except:
import socket
CONTENT = b"""\
HTTP/1.0 200 OK
Reported by Pylint.
Line: 14
Column: 1
"""
def main(micropython_optimize=False):
s = socket.socket()
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8080)
print("Bind address info:", ai)
Reported by Pylint.
Line: 15
Column: 5
def main(micropython_optimize=False):
s = socket.socket()
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8080)
print("Bind address info:", ai)
addr = ai[0][-1]
Reported by Pylint.
Line: 18
Column: 5
s = socket.socket()
# Binding to all interfaces - server will be accessible to other hosts!
ai = socket.getaddrinfo("0.0.0.0", 8080)
print("Bind address info:", ai)
addr = ai[0][-1]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
Reported by Pylint.
Line: 52
Column: 13
req = client_stream.readline()
print(req)
while True:
h = client_stream.readline()
if h == b"" or h == b"\r\n":
break
print(h)
client_stream.write(CONTENT % counter)
Reported by Pylint.
Line: 53
Column: 16
print(req)
while True:
h = client_stream.readline()
if h == b"" or h == b"\r\n":
break
print(h)
client_stream.write(CONTENT % counter)
client_stream.close()
Reported by Pylint.
tests/basics/exceptpoly2.py
8 issues
Line: 3
Column: 8
try:
raise MemoryError
except Exception:
print("Caught MemoryError via Exception")
try:
raise MemoryError
except MemoryError:
print("Caught MemoryError")
Reported by Pylint.
Line: 13
Column: 8
try:
raise NameError
except Exception:
print("Caught NameError via Exception")
try:
raise NameError
except NameError:
Reported by Pylint.
Line: 33
Column: 8
try:
raise OSError
except Exception:
print("Caught OSError via Exception")
try:
raise OSError
except OSError:
Reported by Pylint.
Line: 53
Column: 8
try:
raise RuntimeError
except Exception:
print("Caught RuntimeError via Exception")
try:
raise RuntimeError
except RuntimeError:
Reported by Pylint.
Line: 63
Column: 8
try:
raise SyntaxError
except Exception:
print("Caught SyntaxError via Exception")
try:
raise SyntaxError
except SyntaxError:
Reported by Pylint.
Line: 73
Column: 8
try:
raise TypeError
except Exception:
print("Caught TypeError via Exception")
try:
raise TypeError
except TypeError:
Reported by Pylint.
Line: 83
Column: 8
try:
raise ValueError
except Exception:
print("Caught ValueError via Exception")
try:
raise ValueError
except ValueError:
Reported by Pylint.
Line: 1
Column: 1
try:
raise MemoryError
except Exception:
print("Caught MemoryError via Exception")
try:
raise MemoryError
except MemoryError:
print("Caught MemoryError")
Reported by Pylint.