The following issues were found

tests/basics/ifexpr.py
6 issues
Using a conditional statement with a constant value
Error

Line: 3 Column: 7

              # test if-expressions

print(1 if 0 else 2)
print(3 if 1 else 4)

def f(x):
    print('a' if x else 'b')
f([])
f([1])

            

Reported by Pylint.

Using a conditional statement with a constant value
Error

Line: 4 Column: 7

              # test if-expressions

print(1 if 0 else 2)
print(3 if 1 else 4)

def f(x):
    print('a' if x else 'b')
f([])
f([1])

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # test if-expressions

print(1 if 0 else 2)
print(3 if 1 else 4)

def f(x):
    print('a' if x else 'b')
f([])
f([1])

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              print(1 if 0 else 2)
print(3 if 1 else 4)

def f(x):
    print('a' if x else 'b')
f([])
f([1])

            

Reported by Pylint.

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

Line: 6 Column: 1

              print(1 if 0 else 2)
print(3 if 1 else 4)

def f(x):
    print('a' if x else 'b')
f([])
f([1])

            

Reported by Pylint.

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

Line: 6 Column: 1

              print(1 if 0 else 2)
print(3 if 1 else 4)

def f(x):
    print('a' if x else 'b')
f([])
f([1])

            

Reported by Pylint.

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

Line: 41 Column: 9

                      yield 2
    except:
        print('raising GeneratorExit')
        raise GeneratorExit

g = gen2()
next(g)
print(g.close())


            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 53 Column: 9

                      yield 1
        yield 2
    except:
        raise ValueError

g = gen3()
next(g)
try:
    print(g.close())

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 1 Column: 1

              def gen1():
    yield 1
    yield 2

# Test that it's possible to close just created gen
g = gen1()
print(g.close())
try:
    next(g)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              def gen1():
    yield 1
    yield 2

# Test that it's possible to close just created gen
g = gen1()
print(g.close())
try:
    next(g)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 35 Column: 1

              

# Throwing GeneratorExit in response to close() is ok
def gen2():
    try:
        yield 1
        yield 2
    except:
        print('raising GeneratorExit')

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 48 Column: 1

              print(g.close())

# Any other exception is propagated to the .close() caller
def gen3():
    try:
        yield 1
        yield 2
    except:
        raise ValueError

            

Reported by Pylint.

tests/basics/generator_args.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              # Handling of "complicated" arg forms to generators
# https://github.com/micropython/micropython/issues/397
def gen(v=5):
    for i in range(v):
        yield i

print(list(gen()))
print(list(gen(v=10)))


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 3 Column: 1

              # Handling of "complicated" arg forms to generators
# https://github.com/micropython/micropython/issues/397
def gen(v=5):
    for i in range(v):
        yield i

print(list(gen()))
print(list(gen(v=10)))


            

Reported by Pylint.

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

Line: 3 Column: 1

              # Handling of "complicated" arg forms to generators
# https://github.com/micropython/micropython/issues/397
def gen(v=5):
    for i in range(v):
        yield i

print(list(gen()))
print(list(gen(v=10)))


            

Reported by Pylint.

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

Line: 11 Column: 1

              print(list(gen(v=10)))


def g(*args, **kwargs):
    for i in args:
        yield i
    for k, v in kwargs.items():
        yield (k, v)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 1

              print(list(gen(v=10)))


def g(*args, **kwargs):
    for i in args:
        yield i
    for k, v in kwargs.items():
        yield (k, v)


            

Reported by Pylint.

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

Line: 14 Column: 12

              def g(*args, **kwargs):
    for i in args:
        yield i
    for k, v in kwargs.items():
        yield (k, v)

print(list(g(1, 2, 3, foo="bar")))

            

Reported by Pylint.

tests/basics/gen_yield_from_stopped.py
6 issues
function already defined line 10
Error

Line: 22 Column: 1

              

# Where "f" is a native generator
def run():
    print((yield from f))


f = zip()
try:

            

Reported by Pylint.

Unreachable code
Error

Line: 6 Column: 5

              def gen():
    return 1
    # This yield is just to make this a generator
    yield

f = gen()

def run():
    print((yield from f))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Yielding from stopped generator is ok and results in None

def gen():
    return 1
    # This yield is just to make this a generator
    yield

f = gen()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 3 Column: 1

              # Yielding from stopped generator is ok and results in None

def gen():
    return 1
    # This yield is just to make this a generator
    yield

f = gen()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 1

              
f = gen()

def run():
    print((yield from f))
    print((yield from f))
    print((yield from f))

try:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

              

# Where "f" is a native generator
def run():
    print((yield from f))


f = zip()
try:

            

Reported by Pylint.

tests/misc/sys_settrace_subdir/sys_settrace_importme.py
6 issues
Using variable 'const' before assignment
Error

Line: 4 Column: 9

              print("Yep, I got imported.")

try:
    x = const(1)
except NameError:
    print("const not defined")

const = lambda x: x


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              print("Yep, I got imported.")

try:
    x = const(1)
except NameError:
    print("const not defined")

const = lambda x: x


            

Reported by Pylint.

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

Line: 13 Column: 1

              _CNT01 = "CONST01"
_CNT02 = const(123)
A123 = const(123)
a123 = const(123)


def dummy():
    return False


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

              a123 = const(123)


def dummy():
    return False


def saysomething():
    print("There, I said it.")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

                  return False


def saysomething():
    print("There, I said it.")


def neverexecuted():
    print("Never got here!")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

                  print("There, I said it.")


def neverexecuted():
    print("Never got here!")


print("Yep, got here")

            

Reported by Pylint.

tests/misc/sys_atexit.py
6 issues
Unable to import 'usys'
Error

Line: 3 Column: 1

              # test sys.atexit() function

import usys

try:
    usys.atexit
except AttributeError:
    print("SKIP")
    raise SystemExit

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 9 Column: 5

                  usys.atexit
except AttributeError:
    print("SKIP")
    raise SystemExit

some_var = None


def do_at_exit():

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # test sys.atexit() function

import usys

try:
    usys.atexit
except AttributeError:
    print("SKIP")
    raise SystemExit

            

Reported by Pylint.

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

Line: 11 Column: 1

                  print("SKIP")
    raise SystemExit

some_var = None


def do_at_exit():
    print("done at exit:", some_var)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

              some_var = None


def do_at_exit():
    print("done at exit:", some_var)


usys.atexit(do_at_exit)


            

Reported by Pylint.

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

Line: 20 Column: 1

              
usys.atexit(do_at_exit)

some_var = "ok"
print("done before exit")

            

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.

examples/network/http_server_simplistic_commented.py
6 issues
No exception type(s) specified
Error

Line: 13 Column: 1

              #
try:
    import usocket as socket
except:
    import socket


CONTENT = b"""\
HTTP/1.0 200 OK

            

Reported by Pylint.

Possible binding to all interfaces.
Security

Line: 36
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b104_hardcoded_bind_all_interfaces.html

                  # local network. Take care when running this on an Internet-connected
    # machine though! Replace "0.0.0.0" with "127.0.0.1" if in doubt, to
    # make the server accessible only on the machine it runs on.
    ai = socket.getaddrinfo("0.0.0.0", 8080)
    print("Bind address info:", ai)
    addr = ai[0][-1]

    # A port on which a socket listened remains inactive during some time.
    # This means that if you run this sample, terminate it, and run again

            

Reported by Bandit.

Missing module docstring
Error

Line: 1 Column: 1

              #
# MicroPython http_server_simplistic.py example
#
# This example shows how to write the smallest possible HTTP
# server in MicroPython. With comments and convenience code
# removed, this example can be compressed literally to ten
# lines. There's a catch though - read comments below for
# details, and use this code only for quick hacks, preferring
# http_server.py for "real thing".

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

              """


def main():
    s = socket.socket()

    # Bind to (allow to be connected on ) all interfaces. This means
    # this server will be accessible to other hosts on your local
    # network, and if your server has direct (non-firewalled) connection

            

Reported by Pylint.

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

Line: 25 Column: 5

              

def main():
    s = socket.socket()

    # Bind to (allow to be connected on ) all interfaces. This means
    # this server will be accessible to other hosts on your local
    # network, and if your server has direct (non-firewalled) connection
    # to the Internet, then to anyone on the Internet. We bind to all

            

Reported by Pylint.

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

Line: 36 Column: 5

                  # local network. Take care when running this on an Internet-connected
    # machine though! Replace "0.0.0.0" with "127.0.0.1" if in doubt, to
    # make the server accessible only on the machine it runs on.
    ai = socket.getaddrinfo("0.0.0.0", 8080)
    print("Bind address info:", ai)
    addr = ai[0][-1]

    # A port on which a socket listened remains inactive during some time.
    # This means that if you run this sample, terminate it, and run again

            

Reported by Pylint.

tests/basics/fun_calldblstar2.py
6 issues
Undefined variable 'foo'
Error

Line: 16 Column: 1

              exec("def foo(*,thisisaverylongargumentname=1):\n print(thisisaverylongargumentname)")

# test default arg
foo()

# the string from the dict should match the interned keyword argument
foo(**args)

            

Reported by Pylint.

Undefined variable 'foo'
Error

Line: 19 Column: 1

              foo()

# the string from the dict should match the interned keyword argument
foo(**args)

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 7 Column: 5

                  exec
except NameError:
    print("SKIP")
    raise SystemExit

# they key in this dict is a string object and is not interned
args = {'thisisaverylongargumentname': 123}

# when this string is executed it will intern the keyword argument

            

Reported by Pylint.

Use of exec
Error

Line: 13 Column: 1

              args = {'thisisaverylongargumentname': 123}

# when this string is executed it will intern the keyword argument
exec("def foo(*,thisisaverylongargumentname=1):\n print(thisisaverylongargumentname)")

# test default arg
foo()

# the string from the dict should match the interned keyword argument

            

Reported by Pylint.

Use of exec detected.
Security

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

              args = {'thisisaverylongargumentname': 123}

# when this string is executed it will intern the keyword argument
exec("def foo(*,thisisaverylongargumentname=1):\n print(thisisaverylongargumentname)")

# test default arg
foo()

# the string from the dict should match the interned keyword argument

            

Reported by Bandit.

Missing module docstring
Error

Line: 1 Column: 1

              # test passing a string object as the key for a keyword argument

try:
    exec
except NameError:
    print("SKIP")
    raise SystemExit

# they key in this dict is a string object and is not interned

            

Reported by Pylint.

tests/internal_bench/func_args-1.1-pos_1.py
6 issues
Unused argument 'a'
Error

Line: 4 Column: 10

              import bench


def func(a):
    pass


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

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import bench


def func(a):
    pass


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

            

Reported by Pylint.

Module name "1-pos_1" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              import bench


def func(a):
    pass


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

            

Reported by Pylint.

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

Line: 4 Column: 1

              import bench


def func(a):
    pass


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

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 4 Column: 1

              import bench


def func(a):
    pass


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

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

                  pass


def test(num):
    for i in iter(range(num)):
        func(i)


bench.run(test)

            

Reported by Pylint.