The following issues were found
tests/micropython/viper_subscr.py
9 issues
Line: 4
Column: 2
# test standard Python subscr using viper types
@micropython.viper
def get(dest, i: int):
i += 1
return dest[i]
Reported by Pylint.
Line: 10
Column: 2
return dest[i]
@micropython.viper
def set(dest, i: int, val: int):
i += 1
dest[i] = val + 1
Reported by Pylint.
Line: 5
Column: 15
@micropython.viper
def get(dest, i: int):
i += 1
return dest[i]
@micropython.viper
Reported by Pylint.
Line: 11
Column: 15
@micropython.viper
def set(dest, i: int, val: int):
i += 1
dest[i] = val + 1
ar = [i for i in range(3)]
Reported by Pylint.
Line: 11
Column: 1
@micropython.viper
def set(dest, i: int, val: int):
i += 1
dest[i] = val + 1
ar = [i for i in range(3)]
Reported by Pylint.
Line: 1
Column: 1
# test standard Python subscr using viper types
@micropython.viper
def get(dest, i: int):
i += 1
return dest[i]
Reported by Pylint.
Line: 5
Column: 1
@micropython.viper
def get(dest, i: int):
i += 1
return dest[i]
@micropython.viper
Reported by Pylint.
Line: 11
Column: 1
@micropython.viper
def set(dest, i: int, val: int):
i += 1
dest[i] = val + 1
ar = [i for i in range(3)]
Reported by Pylint.
Line: 16
Column: 1
dest[i] = val + 1
ar = [i for i in range(3)]
for i in range(len(ar)):
set(ar, i - 1, i)
print(ar)
Reported by Pylint.
tests/basics/logic_constfolding.py
9 issues
Line: 12
Column: 12
return False
print(0 or False)
print(1 or foo)
print(f_false() or 1 or foo)
print(f_false() or 1 or f_true())
print(0 and foo)
print(1 and True)
Reported by Pylint.
Line: 13
Column: 25
print(0 or False)
print(1 or foo)
print(f_false() or 1 or foo)
print(f_false() or 1 or f_true())
print(0 and foo)
print(1 and True)
print(f_true() and 0 and foo)
Reported by Pylint.
Line: 16
Column: 13
print(f_false() or 1 or foo)
print(f_false() or 1 or f_true())
print(0 and foo)
print(1 and True)
print(f_true() and 0 and foo)
print(f_true() and 1 and f_false())
print(not 0)
Reported by Pylint.
Line: 18
Column: 26
print(0 and foo)
print(1 and True)
print(f_true() and 0 and foo)
print(f_true() and 1 and f_false())
print(not 0)
print(not False)
print(not 1)
Reported by Pylint.
Line: 1
Column: 1
# tests logical constant folding in parser
def f_true():
print('f_true')
return True
def f_false():
print('f_false')
return False
Reported by Pylint.
Line: 3
Column: 1
# tests logical constant folding in parser
def f_true():
print('f_true')
return True
def f_false():
print('f_false')
return False
Reported by Pylint.
Line: 7
Column: 1
print('f_true')
return True
def f_false():
print('f_false')
return False
print(0 or False)
print(1 or foo)
Reported by Pylint.
Line: 25
Column: 7
print(not False)
print(not 1)
print(not True)
print(not not 0)
print(not not 1)
Reported by Pylint.
Line: 26
Column: 7
print(not 1)
print(not True)
print(not not 0)
print(not not 1)
Reported by Pylint.
tests/extmod/uasyncio_set_exception_handler.py
9 issues
Line: 10
Column: 9
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
def custom_handler(loop, context):
print("custom_handler", repr(context["exception"]))
Reported by Pylint.
Line: 13
Column: 20
raise SystemExit
def custom_handler(loop, context):
print("custom_handler", repr(context["exception"]))
async def task(i):
# Raise with 2 args so exception prints the same in uPy and CPython
Reported by Pylint.
Line: 30
Column: 11
# Set exception handler and test it was set
loop.set_exception_handler(custom_handler)
print(loop.get_exception_handler() == custom_handler)
# Create a task that raises and uses the custom exception handler
asyncio.create_task(task(0))
print("sleep")
for _ in range(2):
Reported by Pylint.
Line: 1
Column: 1
# Test that tasks return their value correctly to the caller
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
def custom_handler(loop, context):
print("custom_handler", repr(context["exception"]))
async def task(i):
# Raise with 2 args so exception prints the same in uPy and CPython
Reported by Pylint.
Line: 17
Column: 1
print("custom_handler", repr(context["exception"]))
async def task(i):
# Raise with 2 args so exception prints the same in uPy and CPython
raise ValueError(i, i + 1)
async def main():
Reported by Pylint.
Line: 22
Column: 1
raise ValueError(i, i + 1)
async def main():
loop = asyncio.get_event_loop()
# Check default exception handler, should be None
print(loop.get_exception_handler())
Reported by Pylint.
Line: 46
Column: 5
await asyncio.sleep(0)
# Create a task, let it run, then await it (no exception should be printed)
t = asyncio.create_task(task(3))
await asyncio.sleep(0)
try:
await t
except ValueError as er:
print(repr(er))
Reported by Pylint.
Line: 50
Column: 5
await asyncio.sleep(0)
try:
await t
except ValueError as er:
print(repr(er))
print("done")
Reported by Pylint.
ports/stm32/boards/NUCLEO_WB55/rfcore_makefirmware.py
9 issues
Line: 1
Column: 1
#!/usr/bin/env python3
#
# This file is part of the MicroPython project, http://micropython.org/
#
# The MIT License (MIT)
#
# Copyright (c) 2020 Jim Mussared
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
Reported by Pylint.
Line: 46
Column: 1
}
def main(src_path, dest_path):
for src_file, dest_file in _FIRMWARE_FILES.items():
src_file = os.path.join(src_path, src_file)
dest_file = os.path.join(dest_path, dest_file)
if not os.path.exists(src_file):
print("Unable to find: {}".format(src_file))
Reported by Pylint.
Line: 53
Column: 9
if not os.path.exists(src_file):
print("Unable to find: {}".format(src_file))
continue
sz = 0
with open(src_file, "rb") as src:
with open(dest_file, "wb") as dest:
while True:
b = src.read(4)
if not b:
Reported by Pylint.
Line: 57
Column: 21
with open(src_file, "rb") as src:
with open(dest_file, "wb") as dest:
while True:
b = src.read(4)
if not b:
break
(v,) = struct.unpack("<I", b)
v ^= _OBFUSCATION_KEY
dest.write(struct.pack("<I", v))
Reported by Pylint.
Line: 60
Column: 22
b = src.read(4)
if not b:
break
(v,) = struct.unpack("<I", b)
v ^= _OBFUSCATION_KEY
dest.write(struct.pack("<I", v))
sz += 4
print("Written {} ({} bytes)".format(dest_file, sz))
Reported by Pylint.
Line: 61
Column: 21
if not b:
break
(v,) = struct.unpack("<I", b)
v ^= _OBFUSCATION_KEY
dest.write(struct.pack("<I", v))
sz += 4
print("Written {} ({} bytes)".format(dest_file, sz))
Reported by Pylint.
Line: 63
Column: 21
(v,) = struct.unpack("<I", b)
v ^= _OBFUSCATION_KEY
dest.write(struct.pack("<I", v))
sz += 4
print("Written {} ({} bytes)".format(dest_file, sz))
if __name__ == "__main__":
if len(sys.argv) != 3:
Reported by Pylint.
Line: 72
Column: 1
print("Usage: {} src_path dest_path".format(sys.argv[0]))
print()
print(
'"src_path" should be the location of the ST binaries from https://github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x'
)
print(
'"dest_path" will be where fus_102.bin, fus_110.bin, and ws_ble_hci.bin will be written to.'
)
sys.exit(1)
Reported by Pylint.
Line: 75
Column: 1
'"src_path" should be the location of the ST binaries from https://github.com/STMicroelectronics/STM32CubeWB/tree/master/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x'
)
print(
'"dest_path" will be where fus_102.bin, fus_110.bin, and ws_ble_hci.bin will be written to.'
)
sys.exit(1)
main(sys.argv[1], sys.argv[2])
Reported by Pylint.
tests/perf_bench/viper_call1c.py
9 issues
Line: 1
Column: 2
@micropython.viper
def f1c(x: int) -> int:
return x
@micropython.native
def call(r):
f = f1c
for _ in r:
Reported by Pylint.
Line: 6
Column: 2
return x
@micropython.native
def call(r):
f = f1c
for _ in r:
f(1)
Reported by Pylint.
Line: 1
Column: 1
@micropython.viper
def f1c(x: int) -> int:
return x
@micropython.native
def call(r):
f = f1c
for _ in r:
Reported by Pylint.
Line: 2
Column: 1
@micropython.viper
def f1c(x: int) -> int:
return x
@micropython.native
def call(r):
f = f1c
for _ in r:
Reported by Pylint.
Line: 2
Column: 1
@micropython.viper
def f1c(x: int) -> int:
return x
@micropython.native
def call(r):
f = f1c
for _ in r:
Reported by Pylint.
Line: 7
Column: 1
@micropython.native
def call(r):
f = f1c
for _ in r:
f(1)
Reported by Pylint.
Line: 7
Column: 1
@micropython.native
def call(r):
f = f1c
for _ in r:
f(1)
Reported by Pylint.
Line: 8
Column: 5
@micropython.native
def call(r):
f = f1c
for _ in r:
f(1)
bm_params = {
Reported by Pylint.
Line: 21
Column: 1
}
def bm_setup(params):
return lambda: call(range(params[0])), lambda: (params[0] // 1000, None)
Reported by Pylint.
tests/basics/try3.py
9 issues
Line: 5
Column: 9
def f():
try:
foo()
except:
print("except 1")
try:
baz()
except:
Reported by Pylint.
Line: 9
Column: 13
except:
print("except 1")
try:
baz()
except:
print("except 2")
bar()
try:
Reported by Pylint.
Line: 12
Column: 9
baz()
except:
print("except 2")
bar()
try:
f()
except:
print("f except")
Reported by Pylint.
Line: 6
Column: 5
def f():
try:
foo()
except:
print("except 1")
try:
baz()
except:
print("except 2")
Reported by Pylint.
Line: 10
Column: 9
print("except 1")
try:
baz()
except:
print("except 2")
bar()
try:
f()
Reported by Pylint.
Line: 16
Column: 1
try:
f()
except:
print("f except")
Reported by Pylint.
Line: 1
Column: 1
# nested exceptions
def f():
try:
foo()
except:
print("except 1")
try:
baz()
Reported by Pylint.
Line: 3
Column: 1
# nested exceptions
def f():
try:
foo()
except:
print("except 1")
try:
baz()
Reported by Pylint.
Line: 3
Column: 1
# nested exceptions
def f():
try:
foo()
except:
print("except 1")
try:
baz()
Reported by Pylint.
tests/extmod/uzlib_decompio_gz.py
9 issues
Line: 6
Column: 5
import uio as io
except ImportError:
print("SKIP")
raise SystemExit
# gzip bitstream
buf = io.BytesIO(
b"\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
Reported by Pylint.
Line: 1
Column: 1
try:
import uzlib as zlib
import uio as io
except ImportError:
print("SKIP")
raise SystemExit
# gzip bitstream
Reported by Pylint.
Line: 11
Column: 1
# gzip bitstream
buf = io.BytesIO(
b"\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
)
inp = zlib.DecompIO(buf, 16 + 8)
print(buf.seek(0, 1))
print(inp.read(1))
print(buf.seek(0, 1))
Reported by Pylint.
Line: 26
Column: 1
# Check FHCRC field
buf = io.BytesIO(
b"\x1f\x8b\x08\x02\x99\x0c\xe5W\x00\x03\x00\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
)
inp = zlib.DecompIO(buf, 16 + 8)
print(inp.read())
# Check FEXTRA field
Reported by Pylint.
Line: 33
Column: 1
# Check FEXTRA field
buf = io.BytesIO(
b"\x1f\x8b\x08\x04\x99\x0c\xe5W\x00\x03\x01\x00X\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
)
inp = zlib.DecompIO(buf, 16 + 8)
print(inp.read())
# broken header
Reported by Pylint.
Line: 40
Column: 1
# broken header
buf = io.BytesIO(
b"\x1f\x8c\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x05\x00\x00\x00"
)
try:
inp = zlib.DecompIO(buf, 16 + 8)
except ValueError:
print("ValueError")
Reported by Pylint.
Line: 49
Column: 1
# broken crc32
buf = io.BytesIO(
b"\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa7\x106\x05\x00\x00\x00"
)
inp = zlib.DecompIO(buf, 16 + 8)
try:
inp.read(6)
except OSError as e:
Reported by Pylint.
Line: 54
Column: 1
inp = zlib.DecompIO(buf, 16 + 8)
try:
inp.read(6)
except OSError as e:
print(repr(e))
# broken uncompressed size - not checked so far
# buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x06\x00\x00\x00')
# inp = zlib.DecompIO(buf, 16 + 8)
Reported by Pylint.
Line: 58
Column: 1
print(repr(e))
# broken uncompressed size - not checked so far
# buf = io.BytesIO(b'\x1f\x8b\x08\x08\x99\x0c\xe5W\x00\x03hello\x00\xcbH\xcd\xc9\xc9\x07\x00\x86\xa6\x106\x06\x00\x00\x00')
# inp = zlib.DecompIO(buf, 16 + 8)
# inp.read(6)
Reported by Pylint.
tests/extmod/machine_pinbase.py
9 issues
Line: 6
Column: 5
import umachine as machine
except ImportError:
import machine
machine.PinBase
except:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 9
Column: 5
machine.PinBase
except:
print("SKIP")
raise SystemExit
class MyPin(machine.PinBase):
def __init__(self):
print("__init__")
Reported by Pylint.
Line: 1
Column: 1
try:
try:
import umachine as machine
except ImportError:
import machine
machine.PinBase
except:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 12
Column: 1
raise SystemExit
class MyPin(machine.PinBase):
def __init__(self):
print("__init__")
self.v = False
def value(self, v=None):
Reported by Pylint.
Line: 12
Column: 1
raise SystemExit
class MyPin(machine.PinBase):
def __init__(self):
print("__init__")
self.v = False
def value(self, v=None):
Reported by Pylint.
Line: 15
Column: 9
class MyPin(machine.PinBase):
def __init__(self):
print("__init__")
self.v = False
def value(self, v=None):
print("value:", v)
if v is None:
self.v = not self.v
Reported by Pylint.
Line: 17
Column: 5
print("__init__")
self.v = False
def value(self, v=None):
print("value:", v)
if v is None:
self.v = not self.v
return int(self.v)
Reported by Pylint.
Line: 17
Column: 5
print("__init__")
self.v = False
def value(self, v=None):
print("value:", v)
if v is None:
self.v = not self.v
return int(self.v)
Reported by Pylint.
Line: 17
Column: 5
print("__init__")
self.v = False
def value(self, v=None):
print("value:", v)
if v is None:
self.v = not self.v
return int(self.v)
Reported by Pylint.
extmod/uasyncio/lock.py
9 issues
Line: 4
Column: 1
# MicroPython uasyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George
from . import core
# Lock class for primitive mutex capability
class Lock:
def __init__(self):
# The state can take the following values:
Reported by Pylint.
Line: 26
Column: 13
if self.waiting.peek():
# Task(s) waiting on lock, schedule next Task
self.state = self.waiting.pop_head()
core._task_queue.push_head(self.state)
else:
# No Task waiting so unlock
self.state = 0
async def acquire(self):
Reported by Pylint.
Line: 1
Column: 1
# MicroPython uasyncio module
# MIT license; Copyright (c) 2019-2020 Damien P. George
from . import core
# Lock class for primitive mutex capability
class Lock:
def __init__(self):
# The state can take the following values:
Reported by Pylint.
Line: 7
Column: 1
from . import core
# Lock class for primitive mutex capability
class Lock:
def __init__(self):
# The state can take the following values:
# - 0: unlocked
# - 1: locked
# - <Task>: unlocked but this task has been scheduled to acquire the lock next
Reported by Pylint.
Line: 17
Column: 5
# Queue of Tasks waiting to acquire this Lock
self.waiting = core.TaskQueue()
def locked(self):
return self.state == 1
def release(self):
if self.state != 1:
raise RuntimeError("Lock not acquired")
Reported by Pylint.
Line: 20
Column: 5
def locked(self):
return self.state == 1
def release(self):
if self.state != 1:
raise RuntimeError("Lock not acquired")
if self.waiting.peek():
# Task(s) waiting on lock, schedule next Task
self.state = self.waiting.pop_head()
Reported by Pylint.
Line: 31
Column: 5
# No Task waiting so unlock
self.state = 0
async def acquire(self):
if self.state != 0:
# Lock unavailable, put the calling Task on the waiting queue
self.waiting.push_head(core.cur_task)
# Set calling task's data to the lock's queue so it can be removed if needed
core.cur_task.data = self.waiting
Reported by Pylint.
Line: 39
Column: 13
core.cur_task.data = self.waiting
try:
yield
except core.CancelledError as er:
if self.state == core.cur_task:
# Cancelled while pending on resume, schedule next waiting Task
self.state = 1
self.release()
raise er
Reported by Pylint.
Line: 52
Column: 5
async def __aenter__(self):
return await self.acquire()
async def __aexit__(self, exc_type, exc, tb):
return self.release()
Reported by Pylint.
tests/thread/thread_exc1.py
9 issues
Line: 19
Column: 9
pass
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 4
n_finished = 0
Reported by Pylint.
Line: 18
Column: 9
except ValueError:
pass
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 4
Reported by Pylint.
Line: 1
Column: 1
# test raising and catching an exception within a thread
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def foo():
raise ValueError
Reported by Pylint.
Line: 8
Column: 1
import _thread
def foo():
raise ValueError
def thread_entry():
try:
Reported by Pylint.
Line: 8
Column: 1
import _thread
def foo():
raise ValueError
def thread_entry():
try:
Reported by Pylint.
Line: 12
Column: 1
raise ValueError
def thread_entry():
try:
foo()
except ValueError:
pass
with lock:
Reported by Pylint.
Line: 18
Column: 9
except ValueError:
pass
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 4
Reported by Pylint.
Line: 23
Column: 1
lock = _thread.allocate_lock()
n_thread = 4
n_finished = 0
# spawn threads
for i in range(n_thread):
while True:
Reported by Pylint.
Line: 24
Column: 1
lock = _thread.allocate_lock()
n_thread = 4
n_finished = 0
# spawn threads
for i in range(n_thread):
while True:
try:
Reported by Pylint.