[code-quality] False negative for pylint E0203 when using += operator?

Andreas Maier andreas.r.maier at gmx.de
Mon Mar 17 19:40:58 CET 2014


Hi,
I am using PyLint 1.1.0 with Python 2.6, and found that the following
code does not raise E0203 "Access to member '%s' before its
definition line %s", as it should:

     class MyClass1(object):
         def __init__(self):
             self.first += 5   # Does not raise E0203 as it should
             self.first = 0

Just for comparison, when omitting the straight assignment on the
second line of the method, message E1101 is raised, so the instance
attribute is (correctly) recognized to be read before the addition:

     class MyClass2(object):
         def __init__(self):
             self.first += 5   # Correctly raises E1101:
                               #   Instance of 'MyClass2' has no
                               #   'first' member

Also just for comparison, here is code that correctly raises E0203:

     class MyClass3(object):
         def __init__(self):
             self.first = self.sec  # Correctly raises E0203:
                                    #   Access to member 'sec' before
                                    #   its definition line <N>
             self.sec = 0

When researching this behavior, I seem to have found a notice somewhere
stating that the += operator is incorrectly not recognized by PyLint
as reading the value first, but I could not find the notice again,
nor could I find an entry for this issue in the (new) PyLint issues
list at https://bitbucket.org/logilab/pylint/issues/

My questions are:
* Should this be considered a bug in PyLint?
* If so, has this been reported already?

Kind Regards,
Andy




More information about the code-quality mailing list