The following issues were found
tests/basics/builtin_exec.py
26 issues
Line: 10
Column: 7
raise SystemExit
print(exec("def foo(): return 42"))
print(foo())
d = {}
exec("def bar(): return 84", d)
print(d["bar"]())
Reported by Pylint.
Line: 7
Column: 5
exec
except NameError:
print("SKIP")
raise SystemExit
print(exec("def foo(): return 42"))
print(foo())
d = {}
Reported by Pylint.
Line: 9
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
print("SKIP")
raise SystemExit
print(exec("def foo(): return 42"))
print(foo())
d = {}
exec("def bar(): return 84", d)
print(d["bar"]())
Reported by Bandit.
Line: 9
Column: 7
print("SKIP")
raise SystemExit
print(exec("def foo(): return 42"))
print(foo())
d = {}
exec("def bar(): return 84", d)
print(d["bar"]())
Reported by Pylint.
Line: 13
Column: 1
print(foo())
d = {}
exec("def bar(): return 84", d)
print(d["bar"]())
# passing None/dict as args to globals/locals
foo = 11
exec('print(foo)')
Reported by Pylint.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
print(foo())
d = {}
exec("def bar(): return 84", d)
print(d["bar"]())
# passing None/dict as args to globals/locals
foo = 11
exec('print(foo)')
Reported by Bandit.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
# passing None/dict as args to globals/locals
foo = 11
exec('print(foo)')
exec('print(foo)', None)
exec('print(foo)', {'foo':3}, None)
exec('print(foo)', None, {'foo':3})
exec('print(foo)', None, {'bar':3})
exec('print(foo)', {'bar':3}, locals())
Reported by Bandit.
Line: 18
Column: 1
# passing None/dict as args to globals/locals
foo = 11
exec('print(foo)')
exec('print(foo)', None)
exec('print(foo)', {'foo':3}, None)
exec('print(foo)', None, {'foo':3})
exec('print(foo)', None, {'bar':3})
exec('print(foo)', {'bar':3}, locals())
Reported by Pylint.
Line: 19
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
# passing None/dict as args to globals/locals
foo = 11
exec('print(foo)')
exec('print(foo)', None)
exec('print(foo)', {'foo':3}, None)
exec('print(foo)', None, {'foo':3})
exec('print(foo)', None, {'bar':3})
exec('print(foo)', {'bar':3}, locals())
Reported by Bandit.
Line: 19
Column: 1
# passing None/dict as args to globals/locals
foo = 11
exec('print(foo)')
exec('print(foo)', None)
exec('print(foo)', {'foo':3}, None)
exec('print(foo)', None, {'foo':3})
exec('print(foo)', None, {'bar':3})
exec('print(foo)', {'bar':3}, locals())
Reported by Pylint.
tests/unicode/unicode_id.py
26 issues
Line: 14
Column: 1
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
def α(β, γ):
δ = β + γ
print(β, γ, δ)
α(1, 2)
Reported by Pylint.
Line: 1
Column: 1
# test unicode in identifiers
# comment
# αβγδϵφζ
# global identifiers
α = 1
αβγ = 2
bβ = 3
Reported by Pylint.
Line: 7
Column: 1
# αβγδϵφζ
# global identifiers
α = 1
αβγ = 2
bβ = 3
βb = 4
print(α, αβγ, bβ, βb)
Reported by Pylint.
Line: 8
Column: 1
# global identifiers
α = 1
αβγ = 2
bβ = 3
βb = 4
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
Reported by Pylint.
Line: 9
Column: 1
# global identifiers
α = 1
αβγ = 2
bβ = 3
βb = 4
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
def α(β, γ):
Reported by Pylint.
Line: 10
Column: 1
α = 1
αβγ = 2
bβ = 3
βb = 4
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
def α(β, γ):
δ = β + γ
Reported by Pylint.
Line: 10
Column: 1
α = 1
αβγ = 2
bβ = 3
βb = 4
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
def α(β, γ):
δ = β + γ
Reported by Pylint.
Line: 14
Column: 1
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
def α(β, γ):
δ = β + γ
print(β, γ, δ)
α(1, 2)
Reported by Pylint.
Line: 14
Column: 1
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
def α(β, γ):
δ = β + γ
print(β, γ, δ)
α(1, 2)
Reported by Pylint.
Line: 14
Column: 1
print(α, αβγ, bβ, βb)
# function, argument, local identifiers
def α(β, γ):
δ = β + γ
print(β, γ, δ)
α(1, 2)
Reported by Pylint.
tests/run-natmodtests.py
25 issues
Line: 13
Column: 1
import argparse
sys.path.append("../tools")
import pyboard
# Paths for host executables
CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3")
MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/micropython-coverage")
Reported by Pylint.
Line: 70
Column: 17
def run_script(self, script):
try:
p = subprocess.run(
self.cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, input=script
)
return p.stdout, None
except subprocess.CalledProcessError as er:
return b"", er
Reported by Pylint.
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) 2019 Damien P. George
import os
import subprocess
import sys
Reported by Pylint.
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) 2019 Damien P. George
import os
import subprocess
import sys
Reported by Pylint.
Line: 8
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
# Copyright (c) 2019 Damien P. George
import os
import subprocess
import sys
import argparse
sys.path.append("../tools")
import pyboard
Reported by Bandit.
Line: 13
Column: 1
import argparse
sys.path.append("../tools")
import pyboard
# Paths for host executables
CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3")
MICROPYTHON = os.getenv("MICROPY_MICROPYTHON", "../ports/unix/micropython-coverage")
Reported by Pylint.
Line: 32
Column: 1
}
# Code to allow a target MicroPython to import an .mpy from RAM
injected_import_hook_code = """\
import usys, uos, uio
class __File(uio.IOBase):
def __init__(self):
self.off = 0
def ioctl(self, request, arg):
Reported by Pylint.
Line: 61
Column: 1
"""
class TargetSubprocess:
def __init__(self, cmd):
self.cmd = cmd
def close(self):
pass
Reported by Pylint.
Line: 65
Column: 5
def __init__(self, cmd):
self.cmd = cmd
def close(self):
pass
def run_script(self, script):
try:
p = subprocess.run(
Reported by Pylint.
Line: 68
Column: 5
def close(self):
pass
def run_script(self, script):
try:
p = subprocess.run(
self.cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, input=script
)
return p.stdout, None
Reported by Pylint.
examples/rp2/pio_1hz.py
25 issues
Line: 4
Column: 1
# Example using PIO to blink an LED and raise an IRQ at 1Hz.
import time
from machine import Pin
import rp2
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink_1hz():
Reported by Pylint.
Line: 5
Column: 1
import time
from machine import Pin
import rp2
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink_1hz():
# fmt: off
Reported by Pylint.
Line: 12
Column: 9
def blink_1hz():
# fmt: off
# Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000
irq(rel(0))
set(pins, 1)
set(x, 31) [5]
label("delay_high")
nop() [29]
jmp(x_dec, "delay_high")
Reported by Pylint.
Line: 12
Column: 5
def blink_1hz():
# fmt: off
# Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000
irq(rel(0))
set(pins, 1)
set(x, 31) [5]
label("delay_high")
nop() [29]
jmp(x_dec, "delay_high")
Reported by Pylint.
Line: 13
Column: 9
# fmt: off
# Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000
irq(rel(0))
set(pins, 1)
set(x, 31) [5]
label("delay_high")
nop() [29]
jmp(x_dec, "delay_high")
Reported by Pylint.
Line: 14
Column: 5
# Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000
irq(rel(0))
set(pins, 1)
set(x, 31) [5]
label("delay_high")
nop() [29]
jmp(x_dec, "delay_high")
# Cycles: 1 + 7 + 32 * (30 + 1) = 1000
Reported by Pylint.
Line: 14
Column: 9
# Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000
irq(rel(0))
set(pins, 1)
set(x, 31) [5]
label("delay_high")
nop() [29]
jmp(x_dec, "delay_high")
# Cycles: 1 + 7 + 32 * (30 + 1) = 1000
Reported by Pylint.
Line: 15
Column: 5
irq(rel(0))
set(pins, 1)
set(x, 31) [5]
label("delay_high")
nop() [29]
jmp(x_dec, "delay_high")
# Cycles: 1 + 7 + 32 * (30 + 1) = 1000
set(pins, 0)
Reported by Pylint.
Line: 16
Column: 5
set(pins, 1)
set(x, 31) [5]
label("delay_high")
nop() [29]
jmp(x_dec, "delay_high")
# Cycles: 1 + 7 + 32 * (30 + 1) = 1000
set(pins, 0)
set(x, 31) [6]
Reported by Pylint.
Line: 17
Column: 5
set(x, 31) [5]
label("delay_high")
nop() [29]
jmp(x_dec, "delay_high")
# Cycles: 1 + 7 + 32 * (30 + 1) = 1000
set(pins, 0)
set(x, 31) [6]
label("delay_low")
Reported by Pylint.
tests/extmod/vfs_basic.py
25 issues
Line: 6
Column: 5
try:
import uos
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 9
Column: 5
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
class Filesystem:
def __init__(self, id, fail=0):
self.id = id
Reported by Pylint.
Line: 13
Column: 24
class Filesystem:
def __init__(self, id, fail=0):
self.id = id
self.fail = fail
def mount(self, readonly, mkfs):
print(self.id, "mount", readonly, mkfs)
Reported by Pylint.
Line: 23
Column: 24
def umount(self):
print(self.id, "umount")
def ilistdir(self, dir):
print(self.id, "ilistdir", dir)
return iter([("a%d" % self.id, 0, 0)])
def chdir(self, dir):
print(self.id, "chdir", dir)
Reported by Pylint.
Line: 27
Column: 21
print(self.id, "ilistdir", dir)
return iter([("a%d" % self.id, 0, 0)])
def chdir(self, dir):
print(self.id, "chdir", dir)
if self.fail:
raise OSError(self.fail)
def getcwd(self):
Reported by Pylint.
Line: 36
Column: 21
print(self.id, "getcwd")
return "dir%d" % self.id
def mkdir(self, path):
print(self.id, "mkdir", path)
def remove(self, path):
print(self.id, "remove", path)
Reported by Pylint.
Line: 39
Column: 22
def mkdir(self, path):
print(self.id, "mkdir", path)
def remove(self, path):
print(self.id, "remove", path)
def rename(self, old_path, new_path):
print(self.id, "rename", old_path, new_path)
Reported by Pylint.
Line: 45
Column: 21
def rename(self, old_path, new_path):
print(self.id, "rename", old_path, new_path)
def rmdir(self, path):
print(self.id, "rmdir", path)
def stat(self, path):
print(self.id, "stat", path)
return (self.id,)
Reported by Pylint.
Line: 48
Column: 20
def rmdir(self, path):
print(self.id, "rmdir", path)
def stat(self, path):
print(self.id, "stat", path)
return (self.id,)
def statvfs(self, path):
print(self.id, "statvfs", path)
Reported by Pylint.
Line: 52
Column: 23
print(self.id, "stat", path)
return (self.id,)
def statvfs(self, path):
print(self.id, "statvfs", path)
return (self.id,)
def open(self, file, mode):
print(self.id, "open", file, mode)
Reported by Pylint.
tests/micropython/import_mpy_native_gc.py
25 issues
Line: 74
Column: 1
# Import the native function.
gc.collect()
from features0 import factorial
# Free the module that contained the function.
del sys.modules["features0"]
# Run a GC cycle which should reclaim the module but not the function.
Reported by Pylint.
Line: 6
Column: 5
try:
import gc, sys, uio, uos
sys.implementation.mpy
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 7
Column: 5
import gc, sys, uio, uos
sys.implementation.mpy
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 8
Column: 5
sys.implementation.mpy
uio.IOBase
uos.mount
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 11
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: 25
Column: 21
self.pos += n
return n
def ioctl(self, req, arg):
return 0
class UserFS:
def __init__(self, files):
Reported by Pylint.
Line: 25
Column: 26
self.pos += n
return n
def ioctl(self, req, arg):
return 0
class UserFS:
def __init__(self, files):
Reported by Pylint.
Line: 44
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])
# Pre-compiled examples/natmod/features0 example for various architectures, keyed
# by the required value of sys.implementation.mpy.
Reported by Pylint.
Line: 84
Column: 5
# Allocate lots of fragmented memory to overwrite anything that was just freed by the GC.
for i in range(1000):
[]
# Run the native function, it should not have been freed or overwritten.
print(factorial(10))
# Unmount and undo path addition.
Reported by Pylint.
Line: 1
Column: 1
# Test that native code loaded from a .mpy file is retained after a GC.
try:
import gc, sys, uio, uos
sys.implementation.mpy
uio.IOBase
uos.mount
except (ImportError, AttributeError):
Reported by Pylint.
tests/inlineasm/asmshift.py
25 issues
Line: 1
Column: 2
@micropython.asm_thumb
def lsl1(r0):
lsl(r0, r0, 1)
print(hex(lsl1(0x123)))
@micropython.asm_thumb
Reported by Pylint.
Line: 3
Column: 5
@micropython.asm_thumb
def lsl1(r0):
lsl(r0, r0, 1)
print(hex(lsl1(0x123)))
@micropython.asm_thumb
Reported by Pylint.
Line: 9
Column: 2
print(hex(lsl1(0x123)))
@micropython.asm_thumb
def lsl23(r0):
lsl(r0, r0, 23)
print(hex(lsl23(1)))
Reported by Pylint.
Line: 11
Column: 5
@micropython.asm_thumb
def lsl23(r0):
lsl(r0, r0, 23)
print(hex(lsl23(1)))
Reported by Pylint.
Line: 17
Column: 2
print(hex(lsl23(1)))
@micropython.asm_thumb
def lsr1(r0):
lsr(r0, r0, 1)
print(hex(lsr1(0x123)))
Reported by Pylint.
Line: 19
Column: 5
@micropython.asm_thumb
def lsr1(r0):
lsr(r0, r0, 1)
print(hex(lsr1(0x123)))
Reported by Pylint.
Line: 25
Column: 2
print(hex(lsr1(0x123)))
@micropython.asm_thumb
def lsr31(r0):
lsr(r0, r0, 31)
print(hex(lsr31(0x80000000)))
Reported by Pylint.
Line: 27
Column: 5
@micropython.asm_thumb
def lsr31(r0):
lsr(r0, r0, 31)
print(hex(lsr31(0x80000000)))
Reported by Pylint.
Line: 33
Column: 2
print(hex(lsr31(0x80000000)))
@micropython.asm_thumb
def asr1(r0):
asr(r0, r0, 1)
print(hex(asr1(0x123)))
Reported by Pylint.
Line: 35
Column: 5
@micropython.asm_thumb
def asr1(r0):
asr(r0, r0, 1)
print(hex(asr1(0x123)))
Reported by Pylint.
tests/extmod/vfs_lfs_corrupt.py
25 issues
Line: 6
Column: 5
try:
import uos
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 7
Column: 5
import uos
uos.VfsLfs1
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 = 1024
Reported by Pylint.
Line: 32
Column: 25
self.data[addr + i] = buf[i]
return self.ret
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: 13
return 0
def corrupt(bdev, block):
addr = block * bdev.ERASE_BLOCK_SIZE
for i in range(bdev.ERASE_BLOCK_SIZE):
bdev.data[addr + i] = i & 0xFF
Reported by Pylint.
Line: 47
Column: 16
bdev.data[addr + i] = i & 0xFF
def create_vfs(bdev, vfs_class):
bdev.ret = 0
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
with vfs.open("f", "w") as f:
for i in range(100):
Reported by Pylint.
Line: 52
Column: 13
vfs_class.mkfs(bdev)
vfs = vfs_class(bdev)
with vfs.open("f", "w") as f:
for i in range(100):
f.write("test")
return vfs
def test(bdev, vfs_class):
Reported by Pylint.
Line: 57
Column: 10
return vfs
def test(bdev, vfs_class):
print("test", vfs_class)
# statvfs
vfs = create_vfs(bdev, vfs_class)
corrupt(bdev, 0)
Reported by Pylint.
Line: 1
Column: 1
# Test for VfsLittle using a RAM device, testing error handling from corrupt block device
try:
import uos
uos.VfsLfs1
uos.VfsLfs2
except (ImportError, AttributeError):
print("SKIP")
Reported by Pylint.
Line: 13
Column: 1
raise SystemExit
class RAMBlockDevice:
ERASE_BLOCK_SIZE = 1024
def __init__(self, blocks):
self.data = bytearray(blocks * self.ERASE_BLOCK_SIZE)
self.ret = 0
Reported by Pylint.
tests/basics/builtin_dir.py
25 issues
Line: 25
Column: 5
# dir of subclass
class A:
def a():
pass
class B(A):
def b():
pass
d = dir(B())
Reported by Pylint.
Line: 28
Column: 5
def a():
pass
class B(A):
def b():
pass
d = dir(B())
print(d.count('a'), d.count('b'))
# dir of class with multiple bases and a common parent
Reported by Pylint.
Line: 35
Column: 5
# dir of class with multiple bases and a common parent
class C(A):
def c():
pass
class D(B, C):
def d():
pass
d = dir(D())
Reported by Pylint.
Line: 38
Column: 5
def c():
pass
class D(B, C):
def d():
pass
d = dir(D())
print(d.count('a'), d.count('b'), d.count('c'), d.count('d'))
Reported by Pylint.
Line: 1
Column: 1
# test builtin dir
# dir of locals
print('__name__' in dir())
# dir of module
try:
import usys as sys
except ImportError:
Reported by Pylint.
Line: 16
Column: 1
# dir of type
print('append' in dir(list))
class Foo:
def __init__(self):
self.x = 1
foo = Foo()
print('__init__' in dir(foo))
print('x' in dir(foo))
Reported by Pylint.
Line: 16
Column: 1
# dir of type
print('append' in dir(list))
class Foo:
def __init__(self):
self.x = 1
foo = Foo()
print('__init__' in dir(foo))
print('x' in dir(foo))
Reported by Pylint.
Line: 18
Column: 9
class Foo:
def __init__(self):
self.x = 1
foo = Foo()
print('__init__' in dir(foo))
print('x' in dir(foo))
# dir of subclass
Reported by Pylint.
Line: 24
Column: 1
print('x' in dir(foo))
# dir of subclass
class A:
def a():
pass
class B(A):
def b():
pass
Reported by Pylint.
Line: 24
Column: 1
print('x' in dir(foo))
# dir of subclass
class A:
def a():
pass
class B(A):
def b():
pass
Reported by Pylint.
tests/inlineasm/asmbcc.py
25 issues
Line: 5
Column: 2
# at the moment only tests beq, narrow and wide versions
@micropython.asm_thumb
def f(r0):
mov(r1, r0)
mov(r0, 10)
cmp(r1, 1)
Reported by Pylint.
Line: 7
Column: 9
@micropython.asm_thumb
def f(r0):
mov(r1, r0)
mov(r0, 10)
cmp(r1, 1)
beq(end)
Reported by Pylint.
Line: 7
Column: 5
@micropython.asm_thumb
def f(r0):
mov(r1, r0)
mov(r0, 10)
cmp(r1, 1)
beq(end)
Reported by Pylint.
Line: 9
Column: 5
def f(r0):
mov(r1, r0)
mov(r0, 10)
cmp(r1, 1)
beq(end)
mov(r0, 20)
cmp(r1, 2)
Reported by Pylint.
Line: 10
Column: 9
mov(r1, r0)
mov(r0, 10)
cmp(r1, 1)
beq(end)
mov(r0, 20)
cmp(r1, 2)
beq_n(end)
Reported by Pylint.
Line: 10
Column: 5
mov(r1, r0)
mov(r0, 10)
cmp(r1, 1)
beq(end)
mov(r0, 20)
cmp(r1, 2)
beq_n(end)
Reported by Pylint.
Line: 11
Column: 9
mov(r0, 10)
cmp(r1, 1)
beq(end)
mov(r0, 20)
cmp(r1, 2)
beq_n(end)
Reported by Pylint.
Line: 11
Column: 5
mov(r0, 10)
cmp(r1, 1)
beq(end)
mov(r0, 20)
cmp(r1, 2)
beq_n(end)
Reported by Pylint.
Line: 13
Column: 5
cmp(r1, 1)
beq(end)
mov(r0, 20)
cmp(r1, 2)
beq_n(end)
mov(r0, 30)
cmp(r1, 3)
Reported by Pylint.
Line: 14
Column: 9
beq(end)
mov(r0, 20)
cmp(r1, 2)
beq_n(end)
mov(r0, 30)
cmp(r1, 3)
beq_w(end)
Reported by Pylint.