The following issues were found

tests/perf_bench/viper_call2a.py
11 issues
Undefined variable 'micropython'
Error

Line: 1 Column: 2

              @micropython.viper
def f2a(x, y):
    return x


@micropython.native
def call(r):
    f = f2a
    for _ in r:

            

Reported by Pylint.

Undefined variable 'micropython'
Error

Line: 6 Column: 2

                  return x


@micropython.native
def call(r):
    f = f2a
    for _ in r:
        f(1, 2)


            

Reported by Pylint.

Unused argument 'y'
Error

Line: 2 Column: 12

              @micropython.viper
def f2a(x, y):
    return x


@micropython.native
def call(r):
    f = f2a
    for _ in r:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              @micropython.viper
def f2a(x, y):
    return x


@micropython.native
def call(r):
    f = f2a
    for _ in r:

            

Reported by Pylint.

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

Line: 2 Column: 1

              @micropython.viper
def f2a(x, y):
    return x


@micropython.native
def call(r):
    f = f2a
    for _ in r:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 2 Column: 1

              @micropython.viper
def f2a(x, y):
    return x


@micropython.native
def call(r):
    f = f2a
    for _ in r:

            

Reported by Pylint.

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

Line: 2 Column: 1

              @micropython.viper
def f2a(x, y):
    return x


@micropython.native
def call(r):
    f = f2a
    for _ in r:

            

Reported by Pylint.

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

Line: 7 Column: 1

              

@micropython.native
def call(r):
    f = f2a
    for _ in r:
        f(1, 2)



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              

@micropython.native
def call(r):
    f = f2a
    for _ in r:
        f(1, 2)



            

Reported by Pylint.

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

Line: 8 Column: 5

              
@micropython.native
def call(r):
    f = f2a
    for _ in r:
        f(1, 2)


bm_params = {

            

Reported by Pylint.

tests/basics/for_break.py
11 issues
Unused variable 'v'
Error

Line: 6 Column: 5

              
def foo():
    seq = [1, 2, 3]
    v = 100
    i = 5
    while i > 0:
        print(i)
        for a in seq:
            if a == 2:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Testcase for break in a for [within bunch of other code]
# https://github.com/micropython/micropython/issues/635

def foo():
    seq = [1, 2, 3]
    v = 100
    i = 5
    while i > 0:
        print(i)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 4 Column: 1

              # Testcase for break in a for [within bunch of other code]
# https://github.com/micropython/micropython/issues/635

def foo():
    seq = [1, 2, 3]
    v = 100
    i = 5
    while i > 0:
        print(i)

            

Reported by Pylint.

Black listed name "foo"
Error

Line: 4 Column: 1

              # Testcase for break in a for [within bunch of other code]
# https://github.com/micropython/micropython/issues/635

def foo():
    seq = [1, 2, 3]
    v = 100
    i = 5
    while i > 0:
        print(i)

            

Reported by Pylint.

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

Line: 6 Column: 5

              
def foo():
    seq = [1, 2, 3]
    v = 100
    i = 5
    while i > 0:
        print(i)
        for a in seq:
            if a == 2:

            

Reported by Pylint.

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

Line: 10 Column: 13

                  i = 5
    while i > 0:
        print(i)
        for a in seq:
            if a == 2:
                break
        i -= 1

foo()

            

Reported by Pylint.

Black listed name "bar"
Error

Line: 18 Column: 1

              foo()

# break from within nested for loop
def bar():
    l = [1, 2, 3]
    for e1 in l:
        print(e1)
        for e2 in l:
            print(e1, e2)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 1

              foo()

# break from within nested for loop
def bar():
    l = [1, 2, 3]
    for e1 in l:
        print(e1)
        for e2 in l:
            print(e1, e2)

            

Reported by Pylint.

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

Line: 19 Column: 5

              
# break from within nested for loop
def bar():
    l = [1, 2, 3]
    for e1 in l:
        print(e1)
        for e2 in l:
            print(e1, e2)
            if e2 == 2:

            

Reported by Pylint.

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

Line: 20 Column: 9

              # break from within nested for loop
def bar():
    l = [1, 2, 3]
    for e1 in l:
        print(e1)
        for e2 in l:
            print(e1, e2)
            if e2 == 2:
                break

            

Reported by Pylint.

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

Line: 8 Column: 9

                      import re
    except ImportError:
        print("SKIP")
        raise SystemExit

try:
    re.sub
except AttributeError:
    print("SKIP")

            

Reported by Pylint.

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

Line: 14 Column: 5

                  re.sub
except AttributeError:
    print("SKIP")
    raise SystemExit


def multiply(m):
    return str(int(m.group(0)) * 2)


            

Reported by Pylint.

Anomalous backslash in string: '\d'. String constant might be missing an r prefix.
Error

Line: 21 Column: 15

                  return str(int(m.group(0)) * 2)


print(re.sub("\d+", multiply, "10 20 30 40 50"))

print(re.sub("\d+", lambda m: str(int(m.group(0)) // 2), "10 20 30 40 50"))


def A():

            

Reported by Pylint.

Anomalous backslash in string: '\d'. String constant might be missing an r prefix.
Error

Line: 23 Column: 15

              
print(re.sub("\d+", multiply, "10 20 30 40 50"))

print(re.sub("\d+", lambda m: str(int(m.group(0)) // 2), "10 20 30 40 50"))


def A():
    return "A"


            

Reported by Pylint.

No exception type(s) specified
Error

Line: 58 Column: 1

              # invalid group
try:
    re.sub("(a)", "b\\2", "a")
except:
    print("invalid group")

# invalid group with very large number (to test overflow in uPy)
try:
    re.sub("(a)", "b\\199999999999999999999999999999999999999", "a")

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 64 Column: 1

              # invalid group with very large number (to test overflow in uPy)
try:
    re.sub("(a)", "b\\199999999999999999999999999999999999999", "a")
except:
    print("invalid group")

# Module function takes str/bytes/re.
print(re.sub("a", "a", "a"))
print(re.sub(b".", b"a", b"a"))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              try:
    import ure as re
except ImportError:
    try:
        import re
    except ImportError:
        print("SKIP")
        raise SystemExit


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 1

                  raise SystemExit


def multiply(m):
    return str(int(m.group(0)) * 2)


print(re.sub("\d+", multiply, "10 20 30 40 50"))


            

Reported by Pylint.

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

Line: 17 Column: 1

                  raise SystemExit


def multiply(m):
    return str(int(m.group(0)) * 2)


print(re.sub("\d+", multiply, "10 20 30 40 50"))


            

Reported by Pylint.

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

Line: 26 Column: 1

              print(re.sub("\d+", lambda m: str(int(m.group(0)) // 2), "10 20 30 40 50"))


def A():
    return "A"


print(re.sub("a", A(), "aBCBABCDabcda."))


            

Reported by Pylint.

tests/inlineasm/asmbitops.py
11 issues
Undefined variable 'micropython'
Error

Line: 1 Column: 2

              @micropython.asm_thumb
def clz(r0):
    clz(r0, r0)


print(clz(0xF0))
print(clz(0x8000))



            

Reported by Pylint.

Too many positional arguments for function call
Error

Line: 3 Column: 5

              @micropython.asm_thumb
def clz(r0):
    clz(r0, r0)


print(clz(0xF0))
print(clz(0x8000))



            

Reported by Pylint.

Undefined variable 'micropython'
Error

Line: 10 Column: 2

              print(clz(0x8000))


@micropython.asm_thumb
def rbit(r0):
    rbit(r0, r0)


print(hex(rbit(0xF0)))

            

Reported by Pylint.

Too many positional arguments for function call
Error

Line: 12 Column: 5

              
@micropython.asm_thumb
def rbit(r0):
    rbit(r0, r0)


print(hex(rbit(0xF0)))
print(hex(rbit(0x8000)))

            

Reported by Pylint.

Positional arguments appear to be out of order
Error

Line: 3 Column: 5

              @micropython.asm_thumb
def clz(r0):
    clz(r0, r0)


print(clz(0xF0))
print(clz(0x8000))



            

Reported by Pylint.

Positional arguments appear to be out of order
Error

Line: 12 Column: 5

              
@micropython.asm_thumb
def rbit(r0):
    rbit(r0, r0)


print(hex(rbit(0xF0)))
print(hex(rbit(0x8000)))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              @micropython.asm_thumb
def clz(r0):
    clz(r0, r0)


print(clz(0xF0))
print(clz(0x8000))



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 2 Column: 1

              @micropython.asm_thumb
def clz(r0):
    clz(r0, r0)


print(clz(0xF0))
print(clz(0x8000))



            

Reported by Pylint.

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

Line: 2 Column: 1

              @micropython.asm_thumb
def clz(r0):
    clz(r0, r0)


print(clz(0xF0))
print(clz(0x8000))



            

Reported by Pylint.

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

Line: 11 Column: 1

              

@micropython.asm_thumb
def rbit(r0):
    rbit(r0, r0)


print(hex(rbit(0xF0)))
print(hex(rbit(0x8000)))

            

Reported by Pylint.

tests/stress/recursive_iternext.py
11 issues
Statement seems to have no effect
Error

Line: 3 Column: 5

              # This tests that recursion with iternext doesn't lead to segfault.
try:
    enumerate
    filter
    map
    max
    zip
except:
    print("SKIP")

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 4 Column: 5

              # This tests that recursion with iternext doesn't lead to segfault.
try:
    enumerate
    filter
    map
    max
    zip
except:
    print("SKIP")

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 5 Column: 5

              try:
    enumerate
    filter
    map
    max
    zip
except:
    print("SKIP")
    raise SystemExit

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 6 Column: 5

                  enumerate
    filter
    map
    max
    zip
except:
    print("SKIP")
    raise SystemExit


            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 7 Column: 5

                  filter
    map
    max
    zip
except:
    print("SKIP")
    raise SystemExit

# We need to pick an N that is large enough to hit the recursion

            

Reported by Pylint.

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

Line: 10 Column: 5

                  zip
except:
    print("SKIP")
    raise SystemExit

# We need to pick an N that is large enough to hit the recursion
# limit, but not too large that we run out of heap memory.
try:
    # large stack/heap, eg unix

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 16 Column: 5

              # limit, but not too large that we run out of heap memory.
try:
    # large stack/heap, eg unix
    [0] * 80000
    N = 5000
except:
    try:
        # medium, eg pyboard
        [0] * 10000

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 18 Column: 1

                  # large stack/heap, eg unix
    [0] * 80000
    N = 5000
except:
    try:
        # medium, eg pyboard
        [0] * 10000
        N = 1000
    except:

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 21 Column: 9

              except:
    try:
        # medium, eg pyboard
        [0] * 10000
        N = 1000
    except:
        # small, eg esp8266
        N = 100


            

Reported by Pylint.

No exception type(s) specified
Error

Line: 23 Column: 5

                      # medium, eg pyboard
        [0] * 10000
        N = 1000
    except:
        # small, eg esp8266
        N = 100

try:
    x = (1, 2)

            

Reported by Pylint.

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

Line: 10 Column: 9

                      import asyncio
    except ImportError:
        print("SKIP")
        raise SystemExit


async def factorial(name, number):
    f = 1
    for i in range(2, number + 1):

            

Reported by Pylint.

Redefining built-in 'id'
Error

Line: 23 Column: 16

                  return f


async def task(id):
    print("start", id)
    await asyncio.sleep(0.2)
    print("end", id)



            

Reported by Pylint.

TODO doesn't work, Task should not forward cancellation from gather to sub-task
Error

Line: 40 Column: 3

                  print(await asyncio.gather(factorial("A", 2), factorial("B", 3), factorial("C", 4)))

    # Cancel a multi gather
    # TODO doesn't work, Task should not forward cancellation from gather to sub-task
    # but rather CancelledError should cancel the gather directly, which will then cancel
    # all sub-tasks explicitly
    # t = asyncio.create_task(gather_task())
    # await asyncio.sleep(0.1)
    # t.cancel()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # test uasyncio.gather() function

try:
    import uasyncio as asyncio
except ImportError:
    try:
        import asyncio
    except ImportError:
        print("SKIP")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

                      raise SystemExit


async def factorial(name, number):
    f = 1
    for i in range(2, number + 1):
        print("Task {}: Compute factorial({})...".format(name, i))
        await asyncio.sleep(0.01)
        f *= i

            

Reported by Pylint.

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

Line: 14 Column: 5

              

async def factorial(name, number):
    f = 1
    for i in range(2, number + 1):
        print("Task {}: Compute factorial({})...".format(name, i))
        await asyncio.sleep(0.01)
        f *= i
    print("Task {}: factorial({}) = {}".format(name, number, f))

            

Reported by Pylint.

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

Line: 18 Column: 9

                  for i in range(2, number + 1):
        print("Task {}: Compute factorial({})...".format(name, i))
        await asyncio.sleep(0.01)
        f *= i
    print("Task {}: factorial({}) = {}".format(name, number, f))
    return f


async def task(id):

            

Reported by Pylint.

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

Line: 23 Column: 1

                  return f


async def task(id):
    print("start", id)
    await asyncio.sleep(0.2)
    print("end", id)



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

                  return f


async def task(id):
    print("start", id)
    await asyncio.sleep(0.2)
    print("end", id)



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 29 Column: 1

                  print("end", id)


async def gather_task():
    print("gather_task")
    await asyncio.gather(task(1), task(2))
    print("gather_task2")



            

Reported by Pylint.

tests/thread/thread_gc1.py
11 issues
Undefined variable 'n_finished'
Error

Line: 23 Column: 9

                  with lock:
        print(list(data) == list(range(256)))
        global n_finished
        n_finished += 1


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

            

Reported by Pylint.

Redefining name 'i' from outer scope (line 31)
Error

Line: 14 Column: 9

                  data = bytearray(i for i in range(256))

    # do some work and call gc.collect() a few times
    for i in range(n):
        for i in range(len(data)):
            data[i] = data[i]
        gc.collect()

    # print whether the data remains intact and indicate we are finished

            

Reported by Pylint.

Redefining name 'i' from outer scope (line 14)
Error

Line: 15 Column: 9

              
    # do some work and call gc.collect() a few times
    for i in range(n):
        for i in range(len(data)):
            data[i] = data[i]
        gc.collect()

    # print whether the data remains intact and indicate we are finished
    with lock:

            

Reported by Pylint.

Using the global statement
Error

Line: 22 Column: 9

                  # print whether the data remains intact and indicate we are finished
    with lock:
        print(list(data) == list(range(256)))
        global n_finished
        n_finished += 1


lock = _thread.allocate_lock()
n_thread = 4

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # test that we can run the garbage collector within threads
#
# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd

import gc
import _thread


def thread_entry(n):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 1

              import _thread


def thread_entry(n):
    # allocate a bytearray and fill it
    data = bytearray(i for i in range(256))

    # do some work and call gc.collect() a few times
    for i in range(n):

            

Reported by Pylint.

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

Line: 9 Column: 1

              import _thread


def thread_entry(n):
    # allocate a bytearray and fill it
    data = bytearray(i for i in range(256))

    # do some work and call gc.collect() a few times
    for i in range(n):

            

Reported by Pylint.

Consider using enumerate instead of iterating with range and len
Error

Line: 15 Column: 9

              
    # do some work and call gc.collect() a few times
    for i in range(n):
        for i in range(len(data)):
            data[i] = data[i]
        gc.collect()

    # print whether the data remains intact and indicate we are finished
    with lock:

            

Reported by Pylint.

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

Line: 22 Column: 9

                  # print whether the data remains intact and indicate we are finished
    with lock:
        print(list(data) == list(range(256)))
        global n_finished
        n_finished += 1


lock = _thread.allocate_lock()
n_thread = 4

            

Reported by Pylint.

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

Line: 27 Column: 1

              

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

# spawn threads
for i in range(n_thread):
    _thread.start_new_thread(thread_entry, (10,))

            

Reported by Pylint.

tests/esp32/partition_ota.py
11 issues
Unable to import 'machine'
Error

Line: 5 Column: 1

              # Running this test requires firmware with an OTA Partition, such as the GENERIC_OTA "board".
# This test also requires patience as it copies the boot partition into the other OTA slot.

import machine
from esp32 import Partition

# start by checking that the running partition table has OTA partitions, 'cause if
# it doesn't there's nothing we can test
cur = Partition(Partition.RUNNING)

            

Reported by Pylint.

Unable to import 'esp32'
Error

Line: 6 Column: 1

              # This test also requires patience as it copies the boot partition into the other OTA slot.

import machine
from esp32 import Partition

# start by checking that the running partition table has OTA partitions, 'cause if
# it doesn't there's nothing we can test
cur = Partition(Partition.RUNNING)
cur_name = cur.info()[4]

            

Reported by Pylint.

Unable to import 'uos'
Error

Line: 25 Column: 1

              

# replace boot.py with the test code that will run on each reboot
import uos

try:
    uos.rename("boot.py", "boot-orig.py")
except:
    pass

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 29 Column: 1

              
try:
    uos.rename("boot.py", "boot-orig.py")
except:
    pass
with open("boot.py", "w") as f:
    f.write("DEBUG=" + str(DEBUG))
    f.write(
        """

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Test ESP32 OTA updates, including automatic roll-back.
# Running this test requires firmware with an OTA Partition, such as the GENERIC_OTA "board".
# This test also requires patience as it copies the boot partition into the other OTA slot.

import machine
from esp32 import Partition

# start by checking that the running partition table has OTA partitions, 'cause if
# it doesn't there's nothing we can test

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

              DEBUG = True


def log(*args):
    if DEBUG:
        print(*args)


# replace boot.py with the test code that will run on each reboot

            

Reported by Pylint.

third party import "import uos" should be placed before "from esp32 import Partition"
Error

Line: 25 Column: 1

              

# replace boot.py with the test code that will run on each reboot
import uos

try:
    uos.rename("boot.py", "boot-orig.py")
except:
    pass

            

Reported by Pylint.

Import "import uos" should be placed at the top of the module
Error

Line: 25 Column: 1

              

# replace boot.py with the test code that will run on each reboot
import uos

try:
    uos.rename("boot.py", "boot-orig.py")
except:
    pass

            

Reported by Pylint.

Try, Except, Pass detected.
Security

Line: 29
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b110_try_except_pass.html

              
try:
    uos.rename("boot.py", "boot-orig.py")
except:
    pass
with open("boot.py", "w") as f:
    f.write("DEBUG=" + str(DEBUG))
    f.write(
        """

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 87 Column: 1

                  )


def copy_partition(src, dest):
    log("Partition copy: {} --> {}".format(src.info(), dest.info()))
    sz = src.info()[3]
    if dest.info()[3] != sz:
        raise ValueError("Sizes don't match: {} vs {}".format(sz, dest.info()[3]))
    addr = 0

            

Reported by Pylint.

tests/basics/types1.py
11 issues
Missing module docstring
Error

Line: 1 Column: 1

              # basic types
# similar test for set type is done in set_type.py

print(bool)
print(int)
print(tuple)
print(list)
print(dict)


            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 10 Column: 7

              print(list)
print(dict)

print(type(bool()) == bool)
print(type(int()) == int)
print(type(tuple()) == tuple)
print(type(list()) == list)
print(type(dict()) == dict)


            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 11 Column: 7

              print(dict)

print(type(bool()) == bool)
print(type(int()) == int)
print(type(tuple()) == tuple)
print(type(list()) == list)
print(type(dict()) == dict)

print(type(False) == bool)

            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 12 Column: 7

              
print(type(bool()) == bool)
print(type(int()) == int)
print(type(tuple()) == tuple)
print(type(list()) == list)
print(type(dict()) == dict)

print(type(False) == bool)
print(type(0) == int)

            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 13 Column: 7

              print(type(bool()) == bool)
print(type(int()) == int)
print(type(tuple()) == tuple)
print(type(list()) == list)
print(type(dict()) == dict)

print(type(False) == bool)
print(type(0) == int)
print(type(()) == tuple)

            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 14 Column: 7

              print(type(int()) == int)
print(type(tuple()) == tuple)
print(type(list()) == list)
print(type(dict()) == dict)

print(type(False) == bool)
print(type(0) == int)
print(type(()) == tuple)
print(type([]) == list)

            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 16 Column: 7

              print(type(list()) == list)
print(type(dict()) == dict)

print(type(False) == bool)
print(type(0) == int)
print(type(()) == tuple)
print(type([]) == list)
print(type({}) == dict)


            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 17 Column: 7

              print(type(dict()) == dict)

print(type(False) == bool)
print(type(0) == int)
print(type(()) == tuple)
print(type([]) == list)
print(type({}) == dict)

try:

            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 18 Column: 7

              
print(type(False) == bool)
print(type(0) == int)
print(type(()) == tuple)
print(type([]) == list)
print(type({}) == dict)

try:
    bool.foo

            

Reported by Pylint.

Using type() instead of isinstance() for a typecheck.
Error

Line: 19 Column: 7

              print(type(False) == bool)
print(type(0) == int)
print(type(()) == tuple)
print(type([]) == list)
print(type({}) == dict)

try:
    bool.foo
except AttributeError:

            

Reported by Pylint.

tests/basics/builtin_getattr.py
10 issues
Missing module docstring
Error

Line: 1 Column: 1

              class A:

    var = 132

    def __init__(self):
        self.var2 = 34

    def meth(self, i):
        return 42 + i

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 1 Column: 1

              class A:

    var = 132

    def __init__(self):
        self.var2 = 34

    def meth(self, i):
        return 42 + i

            

Reported by Pylint.

Missing class docstring
Error

Line: 1 Column: 1

              class A:

    var = 132

    def __init__(self):
        self.var2 = 34

    def meth(self, i):
        return 42 + i

            

Reported by Pylint.

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

Line: 1 Column: 1

              class A:

    var = 132

    def __init__(self):
        self.var2 = 34

    def meth(self, i):
        return 42 + i

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 5

                  def __init__(self):
        self.var2 = 34

    def meth(self, i):
        return 42 + i


a = A()
print(getattr(a, "var"))

            

Reported by Pylint.

Method could be a function
Error

Line: 8 Column: 5

                  def __init__(self):
        self.var2 = 34

    def meth(self, i):
        return 42 + i


a = A()
print(getattr(a, "var"))

            

Reported by Pylint.

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

Line: 21 Column: 1

              print(getattr(a, "va" + "r2"))

# test a class that defines __getattr__ and may raise AttributeError
class B:
    def __getattr__(self, attr):
        if attr == "a":
            return attr
        else:
            raise AttributeError

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 21 Column: 1

              print(getattr(a, "va" + "r2"))

# test a class that defines __getattr__ and may raise AttributeError
class B:
    def __getattr__(self, attr):
        if attr == "a":
            return attr
        else:
            raise AttributeError

            

Reported by Pylint.

Missing class docstring
Error

Line: 21 Column: 1

              print(getattr(a, "va" + "r2"))

# test a class that defines __getattr__ and may raise AttributeError
class B:
    def __getattr__(self, attr):
        if attr == "a":
            return attr
        else:
            raise AttributeError

            

Reported by Pylint.

Unnecessary "else" after "return"
Error

Line: 23 Column: 9

              # test a class that defines __getattr__ and may raise AttributeError
class B:
    def __getattr__(self, attr):
        if attr == "a":
            return attr
        else:
            raise AttributeError
b = B()
print(getattr(b, "a"))

            

Reported by Pylint.