Email Re: [Python-projects] Disabling a message once

from
Benjamin Niemann <pink at odahoda dot de>
subject
Re: [Python-projects] Disabling a message once
date
2005/06/28 18:30
On Sunday 26 June 2005 21:35, Benjamin Niemann wrote:
> Hi,
>
> I think it would be nice, if I could disable a message only once for a
> specific occurance - instead of disabling it module-wide. E.g.
>
> <code>
> try:
>    ...
> except KeyError:
>    # I'll implement error handling later
>    pass
>
> try:
>    ...
> except KeyError:
>    # If key is not in dict, no action required
>    pass
> </code>
>
> I would like to disable the message in the second case, but not in the
> first one.
> How about something like
>
> # pylint: disable-msg-once=W0704
>
> shortly before the line where the issue is detected.
>
> What are your thoughts about this?
Looking at the code of pylint, I think another approach should be easier to 
implement. I propose an extended syntax for the disable-msg directive, e.g.:

# pylint: disable-msg=W0704(+2)

The number in brackets is either a relative line number (starting with + or -) 
or absolute (without +/-) - probably only the relative notations is useful. 
An absolute value of 0 (default, if no (NNN) is appended to the message 
code), implies the current behaviour - the message is disabled module wide. 
Otherwise the message is only disabled at the specified lines.

Example:

try:
    [code]
except Exception, exc:
    # tell pylint that we know what we are doing...
    # pylint: disable-msg=W0703(-2)
    [code]

A working patch is attached (no extensive testing so far, but it does not 
break the testsuite of pylint ;)
It feels a bit like an ugly hack to me, because _module_msg_cats_state now 
contains a mix of booleans and lists...

And another little thing: line 6 in test/fulltest.sh should be
    PYVERSIONS="2.2 2.3 2.4"
instead of
    PYVERSIONS="2.2" "2.3" "2.4"

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/

attachment
is a reply to
has reply