[Python-projects] Order of methods counts for attribute init detection

skip at pobox.com skip at pobox.com
Fri Dec 7 14:17:53 CET 2007


I have this set in my .pylintrc file:

  defining-attr-methods=__init__,__new__,reset

Given this silly class:

    class Foo:
        def __init__(self):
            self.reset()

        def some_method(self, val, t):
            self.val = val
            self.t = t

        def reset(self):
            self.val = None
            self.t = None

pylint complains about self.val and self.t being set in some_method.  If I
reverse the order of the some_method and reset definitions pylint is happy.
It appears that you have to define all initializing methods ahead of any
other methods which might change attribute values otherwise it will
complain.

-- 
Skip Montanaro - skip at pobox.com - http://www.webfast.com/~skip/


More information about the Python-Projects mailing list