How can you make pylint/pychecker "see" setattr

Emin.shopper Martinian.shopper emin.shopper at gmail.com
Tue Dec 11 08:16:03 EST 2007


Dear Experts,

Does anyone know how you can either make pylint "see" setattr or give it
explicit information when you do a "compile time" call to setattr?

For example, imagine that I have the following block of code

class foo:
    def __init__(self):
        for i in [1,2,5]:
           setattr(self,'y%i'i,i*i)

    def baz(self):
        print self.y2


With this code, pylint will complain that y2 does not seem to be a member of
self. Obviously, if the arguments for setattr are not known until run-time,
their is nothing pylint can do. But in the case, the arguments are known at
"compile time" so it would be nice if there was some way to communicate this
to pylint. For example, if I could execute something like
pylint.remember_set(...) that pylint would see, that would be great. I
suspect this probably requires more parsing than pylint does, however.

On a related note, does anyone have a suggestion for a way to create a bunch
of similar properties (e.g., y1, y2, y5, etc.) in a "safe" way that either
pychecker or pylint can check (or at least not complain about)? Obviously I
would use better names than y1, y2, etc., but in the project I'm working on
I often need to many large sets of similar variables. Defining them all "by
hand" is tedious and not very readable. I could define them in a dict or use
setattr, but then I can't get any of the benefits of things like pychecker
or pylint. I suspect that is just a fundamental trade-off but it would be
great if someone has a better idiom.

Thanks,
-Emin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071211/4f716015/attachment.html>


More information about the Python-list mailing list