Python Forum
Pylint/pyflakes/flake8 missed AttributeError - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Pylint/pyflakes/flake8 missed AttributeError (/thread-24549.html)



Pylint/pyflakes/flake8 missed AttributeError - elyoni - Feb-19-2020

Hi,
I have the code
class MainC:
    def __init__(self):
        self.arg1 = None

# Method One, Not working
OBJ_LIST = {}
for i in range(10):
    OBJ_LIST[i] = MainC()

for i in range(10):
    print(OBJ_LIST[i].arg2)  # There is a error here

# Method Two, Also not working
OBJ_LIST = []
for i in range(10):
    OBJ_LIST.append(MainC())

for i in range(10):
    print(OBJ_LIST[i].arg2)  # There is a error here
While I am running pylint/pyflakes/flake8 I don't get any error about attribute error.
What can I do to find that error without running the code

Thanks,
Yoni


RE: Pylint/pyflakes/flake8 missed AttributeError - buran - Feb-19-2020

Can you elaborate what exactly you want to achieve?
You designate lines 5-11 as Method1 and lines 13-19 as Method2, but actually that is where the error is.

The generic answer would be that to find errors in the code one would write tests


RE: Pylint/pyflakes/flake8 missed AttributeError - elyoni - Feb-19-2020

This code is just an example, I want to catch the attribute error while I am writing the code.
I look like if I run a on list of the Objects and use the one of attribute it not verified if it belong to the class