~ubuntu-branches/ubuntu/trusty/pylint/trusty

« back to all changes in this revision

Viewing changes to checkers/imports.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2009-03-27 09:45:39 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090327094539-xe2s86jkbvdv3xhb
Tags: 0.18.0-1
* New upstream release
* debian/copyright
  - added packaging copyright for the work I do
  - clearly separated copyright and license notices, indenting by 4 spaces
  - link to GPL-2 file, not to the generic GPL
* debian/control
  - updated Homepage field
  - bump versions for python-logilab-common and python-logilab-astng depends
  - bump Standard-Versions to 3.8.1 (no changes needed)
* debian/{control, rules}
  - switch from python-central to python-support
* debian/rules
  - 'build' is a dir, we need to clean with 'rm'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2003-2008 LOGILAB S.A. (Paris, FRANCE).
 
1
# Copyright (c) 2003-2009 LOGILAB S.A. (Paris, FRANCE).
2
2
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify it under
20
20
from logilab.common.modutils import is_standard_module, is_relative, \
21
21
     get_module_part
22
22
from logilab.common.ureports import VerbatimText, Paragraph
 
23
from logilab.common.compat import sorted, enumerate
23
24
 
24
25
from logilab import astng
 
26
from logilab.astng.infutils import are_exclusive
25
27
 
26
28
from pylint.utils import expand_modules
27
29
from pylint.interfaces import IASTNGChecker
28
30
from pylint.checkers import BaseChecker, EmptyReport
29
 
from pylint.checkers.utils import are_exclusive
 
31
 
30
32
 
31
33
def get_first_import(context, name, base, level=0):
32
34
    """return the node where [base.]<name> is imported or None if not found
74
76
    """return a string which represents imports as a tree"""
75
77
    lines = []
76
78
    nodes = data.items()
77
 
    for i in range(len(nodes)):
78
 
        mod, (sub, files) = nodes[i]
 
79
    for i, (mod, (sub, files)) in enumerate(sorted(nodes, key=lambda x: x[0])):
79
80
        if not files:
80
81
            files = ''
81
82
        else:
325
326
        first = get_first_import(frame, name, basename, level)
326
327
        if isinstance(first, (astng.Import, astng.From)) and first is not node \
327
328
               and not are_exclusive(first, node):
328
 
            self.add_message('W0404', node=node, args=(name, first.lineno))
 
329
            self.add_message('W0404', node=node, args=(name, first.fromlineno))
329
330
        else:
330
331
            root = node.root()
331
332
            if root is frame:
335
336
                return
336
337
            if first is not node and not are_exclusive(first, node):
337
338
                self.add_message('W0404', node=node,
338
 
                                 args=(name, first.lineno))
 
339
                                 args=(name, first.fromlineno))
339
340
 
340
341
        
341
342
    def report_external_dependencies(self, sect, _, dummy):