use .fromlineno instead of .lineno (which is not reliable)

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset1de0c6ed5be4
branchdefault
phasepublic
hiddenno
parent revision#18a43f3b1962 quick fix: use %s rather than %s will avoid crash if lineno is None. See https://bitbucket.org/logilab/pylint/pull-request/6/fixed-a-bug-in-clobber_in_except-causing
child revision#07f199a99d3b redefine cmp under py3k. Closes #120635
files modified by this revision
checkers/imports.py
checkers/utils.py
checkers/variables.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1361790010 -3600
# Mon Feb 25 12:00:10 2013 +0100
# Node ID 1de0c6ed5be45a0180bd9eb4612ff3f2728c220d
# Parent 18a43f3b196245da2f886f6f343d1b480eede5b6
use .fromlineno instead of .lineno (which is not reliable)

diff --git a/checkers/imports.py b/checkers/imports.py
@@ -34,11 +34,11 @@
1      first = None
2      found = False
3      for first in context.body:
4          if first is node:
5              continue
6 -        if first.scope() is node.scope() and first.lineno > node.lineno:
7 +        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
8              continue
9          if isinstance(first, astng.Import):
10              if any(fullname == iname[0] for iname in first.names):
11                  found = True
12                  break
diff --git a/checkers/utils.py b/checkers/utils.py
@@ -1,8 +1,8 @@
13  # pylint: disable=W0611
14  #
15 -# Copyright (c) 2003-2010 LOGILAB S.A. (Paris, FRANCE).
16 +# Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
17  # http://www.logilab.fr/ -- mailto:contact@logilab.fr
18  #
19  # This program is free software; you can redistribute it and/or modify it under
20  # the terms of the GNU General Public License as published by the Free Software
21  # Foundation; either version 2 of the License, or (at your option) any later
@@ -63,11 +63,11 @@
22          else:
23              scope, stmts = node.lookup(name)
24              if (stmts and
25                  not isinstance(stmts[0].ass_type(),
26                                 (astng.Assign, astng.AugAssign, astng.ExceptHandler))):
27 -                return (True, (name, 'outer scope (line %s)' % (stmts[0].lineno,)))
28 +                return (True, (name, 'outer scope (line %s)' % (stmts[0].fromlineno,)))
29      return (False, None)
30 
31 
32  def safe_infer(node):
33      """return the inferred value for the given node.
diff --git a/checkers/variables.py b/checkers/variables.py
@@ -1,6 +1,6 @@
34 -# Copyright (c) 2003-2012 LOGILAB S.A. (Paris, FRANCE).
35 +# Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
36  # http://www.logilab.fr/ -- mailto:contact@logilab.fr
37  #
38  # This program is free software; you can redistribute it and/or modify it under
39  # the terms of the GNU General Public License as published by the Free Software
40  # Foundation; either version 2 of the License, or (at your option) any later
@@ -270,11 +270,11 @@
41          globs = node.root().globals
42          for name, stmt in node.items():
43              if is_inside_except(stmt):
44                  continue
45              if name in globs and not isinstance(stmt, astng.Global):
46 -                line = globs[name][0].lineno
47 +                line = globs[name][0].fromlineno
48                  self.add_message('W0621', args=(name, line), node=stmt)
49              elif is_builtin(name):
50                  # do not print Redefining builtin for additional builtins
51                  self.add_message('W0622', args=name, node=stmt)
52