Email RE: PyLint problems

from
to
Sylvain Thenault <syt at logilab dot fr>
subject
RE: PyLint problems
date
2005/01/25 15:54
Thanks a lot Sylvain!!

Everything worked just fine!!


>Hum, I don't think I've much to do to support 2.4 syntax. At worst it
>should miss some error / warning messages due to the fact that decorator
>and generator comprehension nodes will be ignored (is there some other 
>new syntax ?). To be clearer, I think that currently pylint support the
>python 2.4 syntax if it's running using a 2.4 interpreter. Please tell
>me if i'm wrong.

I don't know... I don't have python 2.4 installed :-(
(still didn't switch, I just wanted to know so I could put it in the pydev
page saying that pylint already supports it)


[]s

Fabio Zadrozny
------------------------------------------------------
Software Developer
ESSS - Engineering Simulation and Scientific Software
www.esss.com.br


-----Original Message-----
From: Sylvain.Thenault@logilab.fr [mailto:Sylvain.Thenault@logilab.fr] 
Sent: terça-feira, 25 de janeiro de 2005 14:28
To: Fabio Zadrozny
Cc: python-projects@logilab.org
Subject: Re: PyLint problems

On Tuesday 25 January à 13:44, Fabio Zadrozny wrote:
> Hi Sylvain,

Hi Fabio,
 
> I have been able to use pylint with qt (that is, it doesn't crash
anymore).

> But now I'm trying to get more from it, there are some things that I still
> cannot do:

> E.g.:

> If I have:


> ---------------------------------------
> import qt

> class WidgetS(qt.QWidget):

>     def returnSize(self):
>         return self.frameSize()

> ---------------------------------------
> I get the error:
> ID:E0201 WidgetS.returnSize: Access to undefined member 'frameSize'

> Even though this is a QWidget method. 
 
ok, I've fixed this in the cvs. The astng builder were ignoring builtins
methods, so qt classes were incomplete. I join to this file the fixed
module (logilab/common/astng/builder.py)
 
> Another problem I have I think is more at the customization level:

> I declare some attributes within a method in properties.create as shown
> below.

> ---------------------------------------
> from coilib.tools import properties

> class Test2:
>     properties.create(x = 0, y = 0)
>     
>     def met1(self):
>         print self.x
> ---------------------------------------

> And get the error:
> ID:E0201 Test2.met1: Access to undefined member 'x'

> I would like to know how could I customize it so that it didn't show that
> error when I declare something the way I do.
 
Hum, that's probably the time to show a custom pylint checkers ! Lucky
guy, I'll use your sample problem for my demonstration ;)

-------------------------------------------------------
from logilab.common import astng

from logilab.pylint.interfaces import IASTNGChecker
from logilab.pylint.checkers import BaseChecker

class MyChecker(BaseChecker):
    """add member attributes defined using my own "properties.create"
    function to the class locals dictionary
    """
    
    __implements__ = IASTNGChecker

    name = 'custom'
    msgs = {}
    options = ()
    # this is important so that your checker is executed before others
    priority = -1 

    def visit_callfunc(self, node):
        if not (isinstance(node.node, astng.Getattr)
                and isinstance(node.node.expr, astng.Name)
                and node.node.expr.name == 'properties'
                and node.node.attrname == 'create'):
            return
        in_class = node.get_frame()
        for param in node.args:
            in_class.locals[param.name] = node

    
def register(linter):
    """required method to auto register this checker"""
    linter.register_checker(MyChecker(linter))
------------------------------------------------------------

put this in logilab/pylint/checkers/ and you're done. Well, there are
probably more error checking to do, but most of the work is done : 

syt@musca:syt$ cat toto.py 
from coilib.tools import properties

class Test2:
    properties.create(x = 0, y = 0)
    
    def met1(self):
        print self.x
syt@musca:syt$ pylint --reports=n toto.py 
No config file found, using default configuration
************* Module toto
C:  0: Black listed name "toto"
W:  0: Missing docstring
W:  0: Missing required attribute "__revision__"
F:  1: Unable to import 'coilib.tools.properties' (No module 'coilib')
W:  3:Test2: Class has no __init__ method
W:  3:Test2: Missing docstring
W:  6:Test2.met1: Missing docstring
R:  3:Test2: Not enough public methods (1/2)


Notice however that you may still have problems in some cases, since a
"checker" is originaly made to check a source code tree, not to add
information on it (the building process is done first).
 
> Anyway, it is working much better now... Next PyDev release will contain
the
> 0.6 version of PyLint!

great !
 
> P.s. any plans of supporting the python 2.4 syntax?

Hum, I don't think I've much to do to support 2.4 syntax. At worst it
should miss some error / warning messages due to the fact that decorator
and generator comprehension nodes will be ignored (is there some other 
new syntax ?). To be clearer, I think that currently pylint support the
python 2.4 syntax if it's running using a 2.4 interpreter. Please tell
me if i'm wrong.

PS: I'm ccing python-projects@logilab.org where discussions about pylint
should be kept.

regards
-- 
Sylvain Thénault                               LOGILAB, Paris (France).

http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org


is a reply to