The following issues were found
drivers/onewire/ds18x20.py
15 issues
Line: 4
Column: 1
# DS18x20 temperature sensor driver for MicroPython.
# MIT license; Copyright (c) 2016 Damien P. George
from micropython import const
_CONVERT = const(0x44)
_RD_SCRATCH = const(0xBE)
_WR_SCRATCH = const(0x4E)
Reported by Pylint.
Line: 1
Column: 1
# DS18x20 temperature sensor driver for MicroPython.
# MIT license; Copyright (c) 2016 Damien P. George
from micropython import const
_CONVERT = const(0x44)
_RD_SCRATCH = const(0xBE)
_WR_SCRATCH = const(0x4E)
Reported by Pylint.
Line: 11
Column: 1
_WR_SCRATCH = const(0x4E)
class DS18X20:
def __init__(self, onewire):
self.ow = onewire
self.buf = bytearray(9)
def scan(self):
Reported by Pylint.
Line: 13
Column: 9
class DS18X20:
def __init__(self, onewire):
self.ow = onewire
self.buf = bytearray(9)
def scan(self):
return [rom for rom in self.ow.scan() if rom[0] in (0x10, 0x22, 0x28)]
Reported by Pylint.
Line: 16
Column: 5
self.ow = onewire
self.buf = bytearray(9)
def scan(self):
return [rom for rom in self.ow.scan() if rom[0] in (0x10, 0x22, 0x28)]
def convert_temp(self):
self.ow.reset(True)
self.ow.writebyte(self.ow.SKIP_ROM)
Reported by Pylint.
Line: 19
Column: 5
def scan(self):
return [rom for rom in self.ow.scan() if rom[0] in (0x10, 0x22, 0x28)]
def convert_temp(self):
self.ow.reset(True)
self.ow.writebyte(self.ow.SKIP_ROM)
self.ow.writebyte(_CONVERT)
def read_scratch(self, rom):
Reported by Pylint.
Line: 24
Column: 5
self.ow.writebyte(self.ow.SKIP_ROM)
self.ow.writebyte(_CONVERT)
def read_scratch(self, rom):
self.ow.reset(True)
self.ow.select_rom(rom)
self.ow.writebyte(_RD_SCRATCH)
self.ow.readinto(self.buf)
if self.ow.crc8(self.buf):
Reported by Pylint.
Line: 33
Column: 5
raise Exception("CRC error")
return self.buf
def write_scratch(self, rom, buf):
self.ow.reset(True)
self.ow.select_rom(rom)
self.ow.writebyte(_WR_SCRATCH)
self.ow.write(buf)
Reported by Pylint.
Line: 39
Column: 5
self.ow.writebyte(_WR_SCRATCH)
self.ow.write(buf)
def read_temp(self, rom):
buf = self.read_scratch(rom)
if rom[0] == 0x10:
if buf[1]:
t = buf[0] >> 1 | 0x80
t = -((~t + 1) & 0xFF)
Reported by Pylint.
Line: 41
Column: 9
def read_temp(self, rom):
buf = self.read_scratch(rom)
if rom[0] == 0x10:
if buf[1]:
t = buf[0] >> 1 | 0x80
t = -((~t + 1) & 0xFF)
else:
t = buf[0] >> 1
Reported by Pylint.
tests/thread/mutate_set.py
15 issues
Line: 22
Column: 9
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 4
n_finished = 0
Reported by Pylint.
Line: 12
Column: 9
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
se.add(i)
assert i in se
se.remove(i)
Reported by Pylint.
Line: 13
Column: 13
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
se.add(i)
assert i in se
se.remove(i)
assert i not in se
Reported by Pylint.
Line: 21
Column: 9
assert i not in se
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 4
Reported by Pylint.
Line: 1
Column: 1
# test concurrent mutating access to a shared set object
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
# the shared set
se = set([-1, -2, -3, -4])
Reported by Pylint.
Line: 11
Column: 1
se = set([-1, -2, -3, -4])
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
se.add(i)
assert i in se
Reported by Pylint.
Line: 11
Column: 1
se = set([-1, -2, -3, -4])
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
se.add(i)
assert i in se
Reported by Pylint.
Line: 11
Column: 1
se = set([-1, -2, -3, -4])
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
se.add(i)
assert i in se
Reported by Pylint.
Line: 11
Column: 1
se = set([-1, -2, -3, -4])
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
se.add(i)
assert i in se
Reported by Pylint.
Line: 11
Column: 1
se = set([-1, -2, -3, -4])
# main thread function
def th(n, lo, hi):
for repeat in range(n):
for i in range(lo, hi):
se.add(i)
assert i in se
Reported by Pylint.
tests/misc/sys_settrace_generator.py
15 issues
Line: 9
Column: 5
sys.settrace
except AttributeError:
print("SKIP")
raise SystemExit
def print_stacktrace(frame, level=0):
print(
"%2d: %s@%s:%s => %s:%d"
Reported by Pylint.
Line: 33
Column: 38
trace_count = 0
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
trace_count += 1
print_stacktrace(frame)
return trace_tick_handler
Reported by Pylint.
Line: 34
Column: 5
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
trace_count += 1
print_stacktrace(frame)
return trace_tick_handler
Reported by Pylint.
Line: 1
Column: 1
# test sys.settrace with generators
import sys
try:
sys.settrace
except AttributeError:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 12
Column: 1
raise SystemExit
def print_stacktrace(frame, level=0):
print(
"%2d: %s@%s:%s => %s:%d"
% (
level,
" ",
Reported by Pylint.
Line: 30
Column: 1
print_stacktrace(frame.f_back, level + 1)
trace_count = 0
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
Reported by Pylint.
Line: 33
Column: 1
trace_count = 0
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
trace_count += 1
print_stacktrace(frame)
return trace_tick_handler
Reported by Pylint.
Line: 34
Column: 5
def trace_tick_handler(frame, event, arg):
global trace_count
print("### trace_handler::main event:", event)
trace_count += 1
print_stacktrace(frame)
return trace_tick_handler
Reported by Pylint.
Line: 41
Column: 1
return trace_tick_handler
def test_generator():
def make_gen():
yield 1 << 0
yield 1 << 1
yield 1 << 2
return 1 << 3
Reported by Pylint.
Line: 49
Column: 5
return 1 << 3
gen = make_gen()
r = 0
try:
r += gen.send(None)
while True:
Reported by Pylint.
tests/basics/class1.py
15 issues
Line: 5
Column: 9
def go():
class C:
def f():
print(1)
def g(self):
print(2)
Reported by Pylint.
Line: 12
Column: 13
print(2)
def set(self, value):
self.value = value
def print(self):
print(self.value)
C.f()
Reported by Pylint.
Line: 1
Column: 1
# basic class
def go():
class C:
def f():
print(1)
def g(self):
print(2)
Reported by Pylint.
Line: 3
Column: 1
# basic class
def go():
class C:
def f():
print(1)
def g(self):
print(2)
Reported by Pylint.
Line: 3
Column: 1
# basic class
def go():
class C:
def f():
print(1)
def g(self):
print(2)
Reported by Pylint.
Line: 4
Column: 5
# basic class
def go():
class C:
def f():
print(1)
def g(self):
print(2)
Reported by Pylint.
Line: 4
Column: 5
# basic class
def go():
class C:
def f():
print(1)
def g(self):
print(2)
Reported by Pylint.
Line: 5
Column: 9
def go():
class C:
def f():
print(1)
def g(self):
print(2)
Reported by Pylint.
Line: 5
Column: 9
def go():
class C:
def f():
print(1)
def g(self):
print(2)
Reported by Pylint.
Line: 8
Column: 9
def f():
print(1)
def g(self):
print(2)
def set(self, value):
self.value = value
Reported by Pylint.
tools/codeformat.py
15 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 Damien P. George
# Copyright (c) 2020 Jim Mussared
#
Reported by Pylint.
Line: 33
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
import itertools
import os
import re
import subprocess
# Relative to top-level repo dir.
PATHS = [
# C
"extmod/*.[ch]",
Reported by Bandit.
Line: 83
Column: 1
PY_EXTS = (".py",)
def list_files(paths, exclusions=None, prefix=""):
files = set()
for pattern in paths:
files.update(glob.glob(os.path.join(prefix, pattern), recursive=True))
for pattern in exclusions or []:
files.difference_update(glob.fnmatch.filter(files, os.path.join(prefix, pattern)))
Reported by Pylint.
Line: 92
Column: 1
return sorted(files)
def fixup_c(filename):
# Read file.
with open(filename) as f:
lines = f.readlines()
# Write out file with fixups.
Reported by Pylint.
Line: 94
Column: 28
def fixup_c(filename):
# Read file.
with open(filename) as f:
lines = f.readlines()
# Write out file with fixups.
with open(filename, "w", newline="") as f:
dedent_stack = []
Reported by Pylint.
Line: 98
Column: 45
lines = f.readlines()
# Write out file with fixups.
with open(filename, "w", newline="") as f:
dedent_stack = []
while lines:
# Get next line.
l = lines.pop(0)
Reported by Pylint.
Line: 102
Column: 13
dedent_stack = []
while lines:
# Get next line.
l = lines.pop(0)
# Dedent #'s to match indent of following line (not previous line).
m = re.match(r"( +)#(if |ifdef |ifndef |elif |else|endif)", l)
if m:
indent = len(m.group(1))
Reported by Pylint.
Line: 105
Column: 13
l = lines.pop(0)
# Dedent #'s to match indent of following line (not previous line).
m = re.match(r"( +)#(if |ifdef |ifndef |elif |else|endif)", l)
if m:
indent = len(m.group(1))
directive = m.group(2)
if directive in ("if ", "ifdef ", "ifndef "):
l_next = lines[0]
Reported by Pylint.
Line: 114
Column: 25
indent_next = len(re.match(r"( *)", l_next).group(1))
if indent - 4 == indent_next and re.match(r" +(} else |case )", l_next):
# This #-line (and all associated ones) needs dedenting by 4 spaces.
l = l[4:]
dedent_stack.append(indent - 4)
else:
# This #-line does not need dedenting.
dedent_stack.append(-1)
else:
Reported by Pylint.
Line: 123
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
if dedent_stack[-1] >= 0:
# This associated #-line needs dedenting to match the #if.
indent_diff = indent - dedent_stack[-1]
assert indent_diff >= 0
l = l[indent_diff:]
if directive == "endif":
dedent_stack.pop()
# Write out line.
Reported by Bandit.
tests/net_inet/tls_num_errors.py
15 issues
Line: 8
Column: 5
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 4
Column: 5
# test that modtls produces a numerical error message when out of heap
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
Reported by Pylint.
Line: 5
Column: 1
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
Reported by Pylint.
Line: 11
Column: 5
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
# test with heap locked to see it switch to number-only error message
def test(addr):
alloc_emergency_exception_buf(256)
Reported by Pylint.
Line: 15
Column: 10
# test with heap locked to see it switch to number-only error message
def test(addr):
alloc_emergency_exception_buf(256)
s = socket.socket()
s.connect(addr)
try:
s.setblocking(False)
Reported by Pylint.
Line: 21
Column: 13
s.connect(addr)
try:
s.setblocking(False)
s = ssl.wrap_socket(s, do_handshake=False)
heap_lock()
print("heap is locked")
while True:
ret = s.write("foo")
if ret:
Reported by Pylint.
Line: 1
Column: 1
# test that modtls produces a numerical error message when out of heap
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
Reported by Pylint.
Line: 4
Column: 5
# test that modtls produces a numerical error message when out of heap
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
Reported by Pylint.
Line: 6
Column: 5
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 6
Column: 5
try:
import usocket as socket, ussl as ssl, sys
except:
import socket, ssl, sys
try:
from micropython import alloc_emergency_exception_buf, heap_lock, heap_unlock
except:
print("SKIP")
raise SystemExit
Reported by Pylint.
extmod/webrepl/websocket_helper.py
15 issues
Line: 2
Column: 5
try:
import usys as sys
except ImportError:
import sys
try:
import ubinascii as binascii
except:
import binascii
Reported by Pylint.
Line: 4
Column: 5
try:
import usys as sys
except ImportError:
import sys
try:
import ubinascii as binascii
except:
import binascii
Reported by Pylint.
Line: 8
Column: 1
try:
import ubinascii as binascii
except:
import binascii
try:
import uhashlib as hashlib
except:
import hashlib
Reported by Pylint.
Line: 12
Column: 1
import binascii
try:
import uhashlib as hashlib
except:
import hashlib
DEBUG = 0
Reported by Pylint.
Line: 1
Column: 1
try:
import usys as sys
except ImportError:
import sys
try:
import ubinascii as binascii
except:
import binascii
Reported by Pylint.
Line: 18
Column: 1
DEBUG = 0
def server_handshake(sock):
clr = sock.makefile("rwb", 0)
l = clr.readline()
# sys.stdout.write(repr(l))
webkey = None
Reported by Pylint.
Line: 20
Column: 5
def server_handshake(sock):
clr = sock.makefile("rwb", 0)
l = clr.readline()
# sys.stdout.write(repr(l))
webkey = None
while 1:
Reported by Pylint.
Line: 26
Column: 9
webkey = None
while 1:
l = clr.readline()
if not l:
raise OSError("EOF in headers")
if l == b"\r\n":
break
# sys.stdout.write(l)
Reported by Pylint.
Line: 32
Column: 9
if l == b"\r\n":
break
# sys.stdout.write(l)
h, v = [x.strip() for x in l.split(b":", 1)]
if DEBUG:
print((h, v))
if h == b"Sec-WebSocket-Key":
webkey = v
Reported by Pylint.
Line: 32
Column: 12
if l == b"\r\n":
break
# sys.stdout.write(l)
h, v = [x.strip() for x in l.split(b":", 1)]
if DEBUG:
print((h, v))
if h == b"Sec-WebSocket-Key":
webkey = v
Reported by Pylint.
tests/extmod/uasyncio_cancel_task.py
15 issues
Line: 10
Column: 9
import asyncio
except ImportError:
print("SKIP")
raise SystemExit
async def task(s, allow_cancel):
try:
print("task start")
Reported by Pylint.
Line: 1
Column: 1
# Test cancelling a task
try:
import uasyncio as asyncio
except ImportError:
try:
import asyncio
except ImportError:
print("SKIP")
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
async def task(s, allow_cancel):
try:
print("task start")
await asyncio.sleep(s)
print("task done")
except asyncio.CancelledError as er:
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
async def task(s, allow_cancel):
try:
print("task start")
await asyncio.sleep(s)
print("task done")
except asyncio.CancelledError as er:
Reported by Pylint.
Line: 18
Column: 5
print("task start")
await asyncio.sleep(s)
print("task done")
except asyncio.CancelledError as er:
print("task cancel")
if allow_cancel:
raise er
Reported by Pylint.
Line: 24
Column: 1
raise er
async def task2(allow_cancel):
print("task 2")
try:
await asyncio.create_task(task(0.05, allow_cancel))
except asyncio.CancelledError as er:
print("task 2 cancel")
Reported by Pylint.
Line: 28
Column: 5
print("task 2")
try:
await asyncio.create_task(task(0.05, allow_cancel))
except asyncio.CancelledError as er:
print("task 2 cancel")
raise er
print("task 2 done")
Reported by Pylint.
Line: 34
Column: 1
print("task 2 done")
async def main():
# Cancel task immediately
t = asyncio.create_task(task(2, True))
print(t.cancel())
# Cancel task after it has started
Reported by Pylint.
Line: 36
Column: 5
async def main():
# Cancel task immediately
t = asyncio.create_task(task(2, True))
print(t.cancel())
# Cancel task after it has started
t = asyncio.create_task(task(2, True))
await asyncio.sleep(0.01)
Reported by Pylint.
Line: 40
Column: 5
print(t.cancel())
# Cancel task after it has started
t = asyncio.create_task(task(2, True))
await asyncio.sleep(0.01)
print(t.cancel())
print("main sleep")
await asyncio.sleep(0.01)
Reported by Pylint.
tests/thread/thread_shared1.py
15 issues
Line: 17
Column: 9
foo(i)
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 2
n_finished = 0
Reported by Pylint.
Line: 8
Column: 9
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
Reported by Pylint.
Line: 8
Column: 9
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
Reported by Pylint.
Line: 12
Column: 18
pass
def thread_entry(n, tup):
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 12
Column: 21
pass
def thread_entry(n, tup):
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 13
Column: 9
def thread_entry(n, tup):
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
Reported by Pylint.
Line: 16
Column: 9
for i in tup:
foo(i)
with lock:
global n_finished
n_finished += 1
lock = _thread.allocate_lock()
n_thread = 2
Reported by Pylint.
Line: 1
Column: 1
# test capability for threads to access a shared immutable data structure
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd
import _thread
def foo(i):
pass
Reported by Pylint.
Line: 8
Column: 1
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
Reported by Pylint.
Line: 8
Column: 1
import _thread
def foo(i):
pass
def thread_entry(n, tup):
for i in tup:
Reported by Pylint.
tools/metrics.py
15 issues
Line: 52
Column: 30
class PortData:
def __init__(self, name, dir, output, make_flags=None):
self.name = name
self.dir = dir
self.output = output
self.make_flags = make_flags
self.needs_mpy_cross = dir not in ("bare-arm", "minimal")
Reported by Pylint.
Line: 46
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
"""
import collections, sys, re, subprocess
MAKE_FLAGS = ["-j3", "CFLAGS_EXTRA=-DNDEBUG"]
class PortData:
Reported by Bandit.
Line: 46
Column: 1
"""
import collections, sys, re, subprocess
MAKE_FLAGS = ["-j3", "CFLAGS_EXTRA=-DNDEBUG"]
class PortData:
Reported by Pylint.
Line: 51
Column: 1
MAKE_FLAGS = ["-j3", "CFLAGS_EXTRA=-DNDEBUG"]
class PortData:
def __init__(self, name, dir, output, make_flags=None):
self.name = name
self.dir = dir
self.output = output
self.make_flags = make_flags
Reported by Pylint.
Line: 51
Column: 1
MAKE_FLAGS = ["-j3", "CFLAGS_EXTRA=-DNDEBUG"]
class PortData:
def __init__(self, name, dir, output, make_flags=None):
self.name = name
self.dir = dir
self.output = output
self.make_flags = make_flags
Reported by Pylint.
Line: 75
Column: 1
}
def syscmd(*args):
sys.stdout.flush()
a2 = []
for a in args:
if isinstance(a, str):
a2.append(a)
Reported by Pylint.
Line: 77
Column: 5
def syscmd(*args):
sys.stdout.flush()
a2 = []
for a in args:
if isinstance(a, str):
a2.append(a)
elif a:
a2.extend(a)
Reported by Pylint.
Line: 78
Column: 9
def syscmd(*args):
sys.stdout.flush()
a2 = []
for a in args:
if isinstance(a, str):
a2.append(a)
elif a:
a2.extend(a)
subprocess.check_call(a2)
Reported by Pylint.
Line: 83
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b603_subprocess_without_shell_equals_true.html
a2.append(a)
elif a:
a2.extend(a)
subprocess.check_call(a2)
def parse_port_list(args):
if not args:
return list(port_data.values())
Reported by Bandit.
Line: 86
Column: 1
subprocess.check_call(a2)
def parse_port_list(args):
if not args:
return list(port_data.values())
else:
ports = []
for arg in args:
Reported by Pylint.