Hi Dustin,

Quoting "Rasener, Dustin M" <dustin.m.rase...@pearson.com>:

Try this:

""" simple pylint example """
def afunc(value_with_long_name):
    """ a doc string """
    value_with_long_name = 3
    # pylint: disable=W0612
    i_want_to_mask_this_warning = value_with_long_name +
value_with_long_name
    # pylint: enable=W0612
    iwant_to_see_this_warning = 7
    print value_with_long_name


Thanks for your answer.
Yes. I know, that this works, but it is a little bit clumsy I think.

Especially as pylint already supports disabling of warnings for only one line (if the line is short enough to append a trailing pylint directive)

The reason I want to use the disable statement is for example for
something like this:

timestamp,name,fsize,permission = get_next_entry()
dosomething_with(timestamp,name,permission)

I know, that fsize is not used, but considering the alternative this is most comprehensible and everything else renders IMHO the code less readable

entries = get_next_entry()
timestamp,name = entries[:2]
permission = entries[3]
dosomething_with(timestamp,name,permission)

Thus I'm really looking for something, which does not clutter the source with one disable statement and one enable statement.


The comment to disable has to precede the offending line.  Also, notice
the call to "enable".  Once you tell pylint to disable a particular
message, it is disabled for the rest of the file, or until the enable
statement.


-----Original Message-----
From: python-projects-boun...@lists.logilab.org
[mailto:python-projects-boun...@lists.logilab.org] On Behalf Of Klaus
Foerster
Sent: Sunday, July 18, 2010 1:31 PM
To: python-projects@lists.logilab.org
Subject: [Python-projects] disabling warning for one long line only
(potential ppylint bug???)

Hi,

I have a small example code snippet with two pylint warnings:

""" simple pylint example """
def afunc(value_with_long_name):
    """ a doc string """
    value_with_long_name = 3
    i_want_to_mask_this_warning = value_with_long_name +
value_with_long_name
    iwant_to_see_this_warning = 7
    print value_with_long_name



Now I would like to supress a pylint warning specifically for one line

The solution seems to be  to add a trailing comment like for example
# pylint: disable=W0612

So my code would look like:

""" simple pylint example """
def afunc(value_with_long_name):
    """ a doc string """
    value_with_long_name = 3
    i_want_to_mask_this_warning = value_with_long_name +
value_with_long_name # pylint: disable=W0612
    iwant_to_see_this_warning = 7
    print value_with_long_name



Now the next two problems arise.
- I get a pylint warning because my line is too long
- my line IS too long, and if I masked the line too long warning it
would become even longer.

The next thing I tried was to use a backslash to shorten my line and
move the pylint warning to the next line

""" simple pylint example """
def afunc(value_with_long_name):
    """ a doc string """
    value_with_long_name = 3
    i_want_to_mask_this_warning = value_with_long_name +
value_with_long_name \
    # pylint: disable=W0612
    iwant_to_see_this_warning = 7
    print value_with_long_name



However this does not work as expected.
it's now the rest of the function, which will ignore pylint warnings,
but not my single line.


Is there a suggested idiom to ignore warnings for long lines ?


For my given example I found a working but not really elegant solution,
which is:

""" simple pylint example """
def afunc(value_with_long_name):
    """ a doc string """
    value_with_long_name = 3
    ( i_want_to_mask_this_warning # pylint: disable=W0612
    )   = value_with_long_name + value_with_long_name
    iwant_to_see_this_warning = 7
    print value_with_long_name



perhaps one solution would be something like:

# pylint: disable_for_next_line=W0612
i_want_to_mask_this_warning = value_with_long_name +
value_with_long_name


Thanks in advance for other suggestions / ideas?





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






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

Reply via email to