Email Re: [Python-projects] 1 Bug(?) / 1 Code Smell / 1 Feature Request

from
to
Marc 'BlackJack' Rintsch <marc at rintsch dot de>
subject
Re: [Python-projects] 1 Bug(?) / 1 Code Smell / 1 Feature Request
date
2005/02/09 10:07
On Tuesday 08 February à 08:33, Marc 'BlackJack' Rintsch wrote:
> Hi,

Hi,
 
> First let me tell you that I like PyLint very much.  It's a great tool
> to check for common mistakes, code conventions and code smells.

Thanks :)
 
> I think there's a bug with meta classes.  The following code lets
> PyLint report an error::

>   class Meta(type):
>       def __init__(mcs, name, bases, dictionary):
>           super(Meta, mcs).__init__(name, bases, dictionary)
>           print mcs._meta_args
>           delattr(mcs, '_meta_args')

>   class Test(object):
>       __metaclass__ = Meta
>       _meta_args = ('foo', 'bar')

> The error is reported at the ``print`` line and says that `_meta_args`
> is not defined.  I guess it's because the attribute is deleted after
> the meta class used it.

no. That just because pylint treat mcs as a regular class, and so think
that the _meta_args attribute should be defined on the class itself.
I'll fix that in the CVS.
 
> ++++

> Defining only static and/or class methods in a class definition is
> IMHO a code smell because it suspiciosly looks like Java code and
> those methods should be functions at module level instead::

>   class Static:
>       def static_method():
>           pass
>       static_method = staticmethod(static_method)

>       def class_method(cls):
>           pass
>       class_method = classmethod(class_method)

> I'm not so sure about class methods but a class with just static
> methods should trigger a warning.

Hum, yes probably. But I guess it's rare enough to be a low priority
feature request. However I'll add it to our tracking tool to not forget
about it.
 
> ++++

> Last but not least a feature request.  When I started with Python I
> didn't get the "a (logical) line ends if all opened parantheses are
> closed" part of the language specs and often used '\' characters to
> break long lines.  Now I prefer the solution with braces and it would
> be nice to have an optional warning for line continuations with '\'.
> It's easy to do with ``find`` and ``grep`` but then it's not part of
> the rating.

I think that would be a good example of custom raw checker :

_______________________________________________________________________

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

class MyRawChecker(BaseChecker):
    """check for line continuations with '\' instead of using triple
    quoted string or parenthesis
    """
    
    __implements__ = IRawChecker

    name = 'custom_raw'
    msgs = {'W9901': ('use \\ for line continuation',
                      ('Used when a \\ is used for a line continuation instead'
                       ' of using triple quoted string or parenthesis.')),
            }
    options = ()

    def process_module(self, stream):
        """process a module
        
        the module's content is accessible via the stream object
        """
        for (lineno, line) in enumerate(stream):
            if line.rstrip().endswith('\\'):
                self.add_message('W9901', line=lineno)

    
def register(linter):
    """required method to auto register this checker"""
    linter.register_checker(MyRawChecker(linter))
_______________________________________________________________________

I've not tested it, but that should do the job :) Just put it in the
logilab/pylint/checkers/ directory.


Thanks for your feedback, regards
-- 
Sylvain Thénault                               LOGILAB, Paris (France).

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

_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects


is a reply to
has reply