The following issues were found

tests/cpydiff/core_locals_eval.py
6 issues
Redefining name 'val' from outer scope (line 7)
Error

Line: 11 Column: 5

              

def test():
    val = 2
    print(val)
    eval("print(val)")


test()

            

Reported by Pylint.

Use of possibly insecure function - consider using safer ast.literal_eval.
Security blacklist

Line: 13
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval

              def test():
    val = 2
    print(val)
    eval("print(val)")


test()

            

Reported by Bandit.

Use of eval
Error

Line: 13 Column: 5

              def test():
    val = 2
    print(val)
    eval("print(val)")


test()

            

Reported by Pylint.

Line too long (250/100)
Error

Line: 4 Column: 1

              """
categories: Core,Runtime
description: Code running in eval() function doesn't have access to local variables
cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name. Effectively, ``eval(expr)`` in MicroPython is equivalent to ``eval(expr, globals(), globals())``.
workaround: Unknown
"""
val = 1



            

Reported by Pylint.

Constant name "val" doesn't conform to UPPER_CASE naming style
Error

Line: 7 Column: 1

              cause: MicroPython doesn't maintain symbolic local environment, it is optimized to an array of slots. Thus, local variables can't be accessed by a name. Effectively, ``eval(expr)`` in MicroPython is equivalent to ``eval(expr, globals(), globals())``.
workaround: Unknown
"""
val = 1


def test():
    val = 2
    print(val)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 1

              val = 1


def test():
    val = 2
    print(val)
    eval("print(val)")



            

Reported by Pylint.

tests/internal_bench/bytebuf-2-join_map_bytes.py
6 issues
Unused variable 'i'
Error

Line: 9 Column: 9

              

def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))


bench.run(test)

            

Reported by Pylint.

Unused variable 'ba2'
Error

Line: 11 Column: 9

              def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))


bench.run(test)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Doing some operation on bytearray
# Pretty weird way - map bytearray thru function, but make sure that
# function return bytes of size 1, then join them together. Surely,
# this is slowest way to do it.
import bench


def test(num):
    for i in iter(range(num // 10000)):

            

Reported by Pylint.

Module name "bytebuf-2-join_map_bytes" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              # Doing some operation on bytearray
# Pretty weird way - map bytearray thru function, but make sure that
# function return bytes of size 1, then join them together. Surely,
# this is slowest way to do it.
import bench


def test(num):
    for i in iter(range(num // 10000)):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              import bench


def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))



            

Reported by Pylint.

Variable name "ba" doesn't conform to snake_case naming style
Error

Line: 10 Column: 9

              
def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = b"".join(map(lambda x: bytes([x + 1]), ba))


bench.run(test)

            

Reported by Pylint.

tests/thread/thread_lock3.py
6 issues
Using the global statement
Error

Line: 13 Column: 5

              

def thread_entry(idx):
    global n_finished
    while True:
        with lock:
            if n_finished == idx:
                break
    print("my turn:", idx)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # test thread coordination using a lock object
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd

import _thread

lock = _thread.allocate_lock()
n_thread = 10
n_finished = 0

            

Reported by Pylint.

Constant name "n_thread" doesn't conform to UPPER_CASE naming style
Error

Line: 8 Column: 1

              import _thread

lock = _thread.allocate_lock()
n_thread = 10
n_finished = 0


def thread_entry(idx):
    global n_finished

            

Reported by Pylint.

Constant name "n_finished" doesn't conform to UPPER_CASE naming style
Error

Line: 9 Column: 1

              
lock = _thread.allocate_lock()
n_thread = 10
n_finished = 0


def thread_entry(idx):
    global n_finished
    while True:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              n_finished = 0


def thread_entry(idx):
    global n_finished
    while True:
        with lock:
            if n_finished == idx:
                break

            

Reported by Pylint.

Constant name "n_finished" doesn't conform to UPPER_CASE naming style
Error

Line: 13 Column: 5

              

def thread_entry(idx):
    global n_finished
    while True:
        with lock:
            if n_finished == idx:
                break
    print("my turn:", idx)

            

Reported by Pylint.

tests/basics/string_large.py
6 issues
Implicit string concatenation found in assignment
Error

Line: 2 Column: 1

              s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"

            

Reported by Pylint.

Line too long (498/100)
Error

Line: 1 Column: 1

              s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"

            

Reported by Pylint.

Constant name "s1" doesn't conform to UPPER_CASE naming style
Error

Line: 1 Column: 1

              s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"

            

Reported by Pylint.

Constant name "s2" doesn't conform to UPPER_CASE naming style
Error

Line: 2 Column: 1

              s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"

            

Reported by Pylint.

Line too long (356/100)
Error

Line: 2 Column: 1

              s1 = "long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string long string"
s2 = "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string" "concatenated string"

            

Reported by Pylint.

tests/internal_bench/bytebuf-3-bytarray_map.py
6 issues
Unused variable 'i'
Error

Line: 7 Column: 9

              

def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = bytearray(map(lambda x: x + 1, ba))


bench.run(test)

            

Reported by Pylint.

Unused variable 'ba2'
Error

Line: 9 Column: 9

              def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = bytearray(map(lambda x: x + 1, ba))


bench.run(test)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Doing some operation on bytearray
# No joins, but still map().
import bench


def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = bytearray(map(lambda x: x + 1, ba))

            

Reported by Pylint.

Module name "bytebuf-3-bytarray_map" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              # Doing some operation on bytearray
# No joins, but still map().
import bench


def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = bytearray(map(lambda x: x + 1, ba))

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              import bench


def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = bytearray(map(lambda x: x + 1, ba))



            

Reported by Pylint.

Variable name "ba" doesn't conform to snake_case naming style
Error

Line: 8 Column: 9

              
def test(num):
    for i in iter(range(num // 10000)):
        ba = bytearray(b"\0" * 1000)
        ba2 = bytearray(map(lambda x: x + 1, ba))


bench.run(test)

            

Reported by Pylint.

tests/extmod/ussl_basic.py
6 issues
Consider explicitly re-raising using the 'from' keyword
Error

Line: 8 Column: 5

                  import ussl as ssl
except ImportError:
    print("SKIP")
    raise SystemExit

# create in client mode
try:
    ss = ssl.wrap_socket(io.BytesIO(), server_hostname="test.example.com")
except OSError as er:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # very basic test of ssl module, just to test the methods exist

try:
    import uio as io
    import ussl as ssl
except ImportError:
    print("SKIP")
    raise SystemExit


            

Reported by Pylint.

Variable name "er" doesn't conform to snake_case naming style
Error

Line: 13 Column: 1

              # create in client mode
try:
    ss = ssl.wrap_socket(io.BytesIO(), server_hostname="test.example.com")
except OSError as er:
    print("wrap_socket:", repr(er))

# create in server mode (can use this object for further tests)
socket = io.BytesIO()
ss = ssl.wrap_socket(socket, server_side=1)

            

Reported by Pylint.

Variable name "er" doesn't conform to snake_case naming style
Error

Line: 42 Column: 1

              socket.seek(0)
try:
    ss.read(8)
except OSError as er:
    print("read:", repr(er))

# close
ss.close()
# close 2nd time

            

Reported by Pylint.

Variable name "er" doesn't conform to snake_case naming style
Error

Line: 53 Column: 1

              # read on closed socket
try:
    ss.read(10)
except OSError as er:
    print("read:", repr(er))

# write on closed socket
try:
    ss.write(b"aaaa")

            

Reported by Pylint.

Variable name "er" doesn't conform to snake_case naming style
Error

Line: 59 Column: 1

              # write on closed socket
try:
    ss.write(b"aaaa")
except OSError as er:
    print("write:", repr(er))

            

Reported by Pylint.

tests/basics/slots_bool_len.py
6 issues
Missing class docstring
Error

Line: 1 Column: 1

              class A:
    def __bool__(self):
        print('__bool__')
        return True
    def __len__(self):
        print('__len__')
        return 1

class B:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              class A:
    def __bool__(self):
        print('__bool__')
        return True
    def __len__(self):
        print('__len__')
        return 1

class B:

            

Reported by Pylint.

Class name "A" doesn't conform to PascalCase naming style
Error

Line: 1 Column: 1

              class A:
    def __bool__(self):
        print('__bool__')
        return True
    def __len__(self):
        print('__len__')
        return 1

class B:

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

                      print('__len__')
        return 1

class B:
    def __len__(self):
        print('__len__')
        return 0

print(bool(A()))

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 9 Column: 1

                      print('__len__')
        return 1

class B:
    def __len__(self):
        print('__len__')
        return 0

print(bool(A()))

            

Reported by Pylint.

Class name "B" doesn't conform to PascalCase naming style
Error

Line: 9 Column: 1

                      print('__len__')
        return 1

class B:
    def __len__(self):
        print('__len__')
        return 0

print(bool(A()))

            

Reported by Pylint.

tests/micropython/viper_error.py
6 issues
Undefined variable 'ViperTypeError'
Error

Line: 7 Column: 26

              def test(code):
    try:
        exec(code)
    except (SyntaxError, ViperTypeError, NotImplementedError) as e:
        print(repr(e))


# viper: annotations must be identifiers
test("@micropython.viper\ndef f(a:1): pass")

            

Reported by Pylint.

Use of exec
Error

Line: 6 Column: 9

              
def test(code):
    try:
        exec(code)
    except (SyntaxError, ViperTypeError, NotImplementedError) as e:
        print(repr(e))


# viper: annotations must be identifiers

            

Reported by Pylint.

Use of exec detected.
Security

Line: 6
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html

              
def test(code):
    try:
        exec(code)
    except (SyntaxError, ViperTypeError, NotImplementedError) as e:
        print(repr(e))


# viper: annotations must be identifiers

            

Reported by Bandit.

Missing module docstring
Error

Line: 1 Column: 1

              # test syntax and type errors specific to viper code generation


def test(code):
    try:
        exec(code)
    except (SyntaxError, ViperTypeError, NotImplementedError) as e:
        print(repr(e))


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 4 Column: 1

              # test syntax and type errors specific to viper code generation


def test(code):
    try:
        exec(code)
    except (SyntaxError, ViperTypeError, NotImplementedError) as e:
        print(repr(e))


            

Reported by Pylint.

Variable name "e" doesn't conform to snake_case naming style
Error

Line: 7 Column: 5

              def test(code):
    try:
        exec(code)
    except (SyntaxError, ViperTypeError, NotImplementedError) as e:
        print(repr(e))


# viper: annotations must be identifiers
test("@micropython.viper\ndef f(a:1): pass")

            

Reported by Pylint.

tests/basics/try_reraise.py
6 issues
The raise statement is not inside an except clause
Error

Line: 17 Column: 5

              
# Can reraise only in except block
try:
    raise
except RuntimeError:
    print("RuntimeError")

            

Reported by Pylint.

The except handler raises immediately
Error

Line: 6 Column: 5

              def f():
    try:
        raise ValueError("val", 3)
    except:
        raise

try:
    f()
except ValueError as e:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Reraising last exception with raise w/o args

def f():
    try:
        raise ValueError("val", 3)
    except:
        raise

try:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 3 Column: 1

              # Reraising last exception with raise w/o args

def f():
    try:
        raise ValueError("val", 3)
    except:
        raise

try:

            

Reported by Pylint.

Function name "f" doesn't conform to snake_case naming style
Error

Line: 3 Column: 1

              # Reraising last exception with raise w/o args

def f():
    try:
        raise ValueError("val", 3)
    except:
        raise

try:

            

Reported by Pylint.

Variable name "e" doesn't conform to snake_case naming style
Error

Line: 11 Column: 1

              
try:
    f()
except ValueError as e:
    print(repr(e))


# Can reraise only in except block
try:

            

Reported by Pylint.

tests/thread/stress_create.py
6 issues
Unused argument 'n'
Error

Line: 14 Column: 18

              import _thread


def thread_entry(n):
    pass


thread_num = 0
while thread_num < 500:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # stress test for creating many threads

try:
    import utime

    sleep_ms = utime.sleep_ms
except ImportError:
    import time


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

              import _thread


def thread_entry(n):
    pass


thread_num = 0
while thread_num < 500:

            

Reported by Pylint.

Argument name "n" doesn't conform to snake_case naming style
Error

Line: 14 Column: 1

              import _thread


def thread_entry(n):
    pass


thread_num = 0
while thread_num < 500:

            

Reported by Pylint.

Constant name "thread_num" doesn't conform to UPPER_CASE naming style
Error

Line: 18 Column: 1

                  pass


thread_num = 0
while thread_num < 500:
    try:
        _thread.start_new_thread(thread_entry, (thread_num,))
        thread_num += 1
    except (MemoryError, OSError) as er:

            

Reported by Pylint.

Variable name "er" doesn't conform to snake_case naming style
Error

Line: 23 Column: 5

                  try:
        _thread.start_new_thread(thread_entry, (thread_num,))
        thread_num += 1
    except (MemoryError, OSError) as er:
        # Cannot create a new thead at this stage, yield for a bit to
        # let existing threads run to completion and free up resources.
        sleep_ms(50)

# wait for the last threads to terminate

            

Reported by Pylint.