W0702 messages should be added to the line of the except handler, not the first line of the body. Closes #81113

authorTorsten Marek <tmarek@google.com>
changesetaefe8a8ab83c
branchdefault
phasepublic
hiddenno
parent revision#354b1851e932 drop unittest2 deprecation warning
child revision#15ecacacac34 Update W0623 to not trigger on code like:
files modified by this revision
ChangeLog
checkers/exceptions.py
test/messages/func_w0702.txt
# HG changeset patch
# User Torsten Marek <tmarek@google.com>
# Date 1319455703 -7200
# Mon Oct 24 13:28:23 2011 +0200
# Node ID aefe8a8ab83c4fb765907a8926586d06da611e95
# Parent 354b1851e932ceea9394e660ecbee7ce9a456311
W0702 messages should be added to the line of the except handler, not the first line of the body. Closes #81113

diff --git a/ChangeLog b/ChangeLog
@@ -1,12 +1,17 @@
1  ChangeLog for PyLint
2  ====================
3 
4  --
5 -    * #81078: Warn if names in  exception handlers clobber overwrite 
6 +    * #81078: Warn if names in  exception handlers clobber overwrite
7        existing names (patch by tmarek@google.com)
8 
9 +    * #81113: Fix W0702 messages appearing with the wrong line number.
10 +      (patch by tmarek@google.com)
11 +
12 +
13 +
14  2011-10-07  --  0.25.0
15      * #74742: make allowed name for first argument of class method configurable
16        (patch by Google)
17 
18      * #74087: handle case where inference of a module return YES; this avoid
diff --git a/checkers/exceptions.py b/checkers/exceptions.py
@@ -149,11 +149,11 @@
19              # single except doing nothing but "pass" without else clause
20              if nb_handlers == 1 and is_empty(handler.body) and not node.orelse:
21                  self.add_message('W0704', node=handler.type or handler.body[0])
22              if handler.type is None:
23                  if nb_handlers == 1 and not is_raising(handler.body):
24 -                    self.add_message('W0702', node=handler.body[0])
25 +                    self.add_message('W0702', node=handler)
26                  # check if a "except:" is followed by some other
27                  # except
28                  elif index < (nb_handlers - 1):
29                      msg = 'empty except clause should always appear last'
30                      self.add_message('E0701', node=node, args=msg)
diff --git a/test/messages/func_w0702.txt b/test/messages/func_w0702.txt
@@ -1,1 +1,1 @@
31 -W: 10: No exception type(s) specified
32 +W:  9: No exception type(s) specified