<html><body>
<p><tt>I hope the indentation is preserved now. Lotus Notes is not Python friendly :(</tt><br>
<br>
<tt>Hi,</tt><br>
<tt><br>
Running pylint on the following code:</tt><br>
<tt>===</tt><br>
<tt>try:</tt><br>
<tt>&nbsp; &nbsp; pass</tt><br>
<tt>finally:</tt><br>
<tt>&nbsp; &nbsp; # pylint: disable-msg=W0201</tt><br>
<tt>&nbsp; &nbsp; pass</tt><br>
<tt>===</tt><br>
<tt>produces this error:</tt><br>
<tt>===</tt><br>
<tt>I: &nbsp;4: Locally disabling W0201</tt><br>
<tt>Traceback (most recent call last):</tt><br>
<tt>&nbsp; File &quot;/usr/bin/pylint&quot;, line 4, in &lt;module&gt;</tt><br>
<tt>&nbsp; &nbsp; lint.Run(sys.argv[1:])</tt><br>
<tt>&nbsp; File &quot;/usr/lib/python2.5/site-packages/pylint/lint.py&quot;, line 901, in __init__</tt><br>
<tt>&nbsp; &nbsp; linter.check(args)</tt><br>
<tt>&nbsp; File &quot;/usr/lib/python2.5/site-packages/pylint/lint.py&quot;, line 492, in check</tt><br>
<tt>&nbsp; &nbsp; self.check_astng_module(astng, checkers)</tt><br>
<tt>&nbsp; File &quot;/usr/lib/python2.5/site-packages/pylint/lint.py&quot;, line 594, in check_astng_module</tt><br>
<tt>&nbsp; &nbsp; self.collect_block_lines(astng, orig_state)</tt><br>
<tt>&nbsp; File &quot;/usr/lib/python2.5/site-packages/pylint/lint.py&quot;, line 428, in collect_block_lines</tt><br>
<tt>&nbsp; &nbsp; self.collect_block_lines(child, msg_state)</tt><br>
<tt>&nbsp; File &quot;/usr/lib/python2.5/site-packages/pylint/lint.py&quot;, line 428, in collect_block_lines</tt><br>
<tt>&nbsp; &nbsp; self.collect_block_lines(child, msg_state)</tt><br>
<tt>&nbsp; File &quot;/usr/lib/python2.5/site-packages/pylint/lint.py&quot;, line 437, in collect_block_lines</tt><br>
<tt>&nbsp; &nbsp; first, last = node.block_range(lineno)</tt><br>
<tt>&nbsp; File &quot;/usr/lib/python2.5/site-packages/logilab/astng/nodes.py&quot;, line 316, in elsed_block_range</tt><br>
<tt>&nbsp; &nbsp; if node.else_:</tt><br>
<tt>AttributeError: TryFinally instance has no attribute 'else_'</tt><br>
<tt>===</tt><br>
<tt><br>
The problem is caused by the &quot;disable-msg&quot; comment. The exact ID <br>
used in the comment doesn't matter, as long as its a number of an <br>
existing message.</tt><br>
<tt><br>
pylint 0.14.0,</tt><br>
<tt>astng 0.17.2, common 0.22.1</tt><br>
<tt>Python 2.5.1 (r251:54863, Mar &nbsp;7 2008, 03:41:45)</tt><br>
<tt><br>
The problem is that the &quot;finally&quot; clause is expected in an attribute named &quot;else_&quot; of the &quot;TryFinally&quot; node, but the attribute is named &quot;final&quot; instead.</tt><br>
<tt>The following patch to astng fixes the problem:</tt><br>
<tt>===</tt><br>
<tt>--- logilab-astng-0.17.2.org/nodes.py 2008-01-14 13:32:55.000000000 +0100</tt><br>
<tt>+++ logilab-astng-0.17.2/nodes.py 2008-07-30 17:13:40.000000000 +0200</tt><br>
<tt>@@ -313,10 +313,11 @@</tt><br>
<tt>&nbsp; &nbsp; &nbsp;&quot;&quot;&quot;</tt><br>
<tt>&nbsp; &nbsp; &nbsp;if lineno == node.source_line():</tt><br>
<tt>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return lineno, lineno</tt><br>
<tt>- &nbsp; &nbsp;if node.else_:</tt><br>
<tt>- &nbsp; &nbsp; &nbsp; &nbsp;if lineno &gt;= node.else_.source_line():</tt><br>
<tt>- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return lineno, node.else_.last_source_line()</tt><br>
<tt>- &nbsp; &nbsp; &nbsp; &nbsp;return lineno, node.else_.source_line() - 1</tt><br>
<tt>+ &nbsp; &nbsp;block = node.final if isinstance(node, TryFinally) else node.else_</tt><br>
<tt>+ &nbsp; &nbsp;if block:</tt><br>
<tt>+ &nbsp; &nbsp; &nbsp; &nbsp;if lineno &gt; node.body.last_source_line():</tt><br>
<tt>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return lineno, block.last_source_line()</tt><br>
<tt>+ &nbsp; &nbsp; &nbsp; &nbsp;return lineno, block.source_line() - 1</tt><br>
<tt>&nbsp; &nbsp; &nbsp;return lineno, last or node.last_source_line()</tt><br>
<tt><br>
 TryFinally.block_range = elsed_block_range</tt><br>
<tt>===</tt><br>
<tt><br>
Note that this patch changes two things:</tt><br>
<tt>1. use &quot;node.final&quot; instead of &quot;node.else_&quot; if node is of type TryFinally</tt><br>
<tt>2. the check whether the given line is in the body or in the else/finally clause is done versus the last line of the body instead of the first line of else/finally clause</tt><br>
<tt><br>
The reason for 2 is that the number given for the first line of the else/finally clause is the number of the first line with a statement on it, while the &quot;lineno&quot; argument is the number of the line with the &quot;# pylint: disable-msg&quot; comment on it, which can be located before the first statement in the block.</tt><br>
<tt><br>
I just realized I used the Python 2.5 style &quot;if&quot; here; if astng supports older Python versions as well, please replace it with a traditional &quot;if&quot;.</tt><br>
<tt><br>
Bye,</tt><br>
<tt>                Maarten</tt><br>
</body></html>