closes #70495: absolute imports fail depending on module path (patch by Jacek Konieczny)

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset2a5477c2a57f
branchdefault
phasepublic
hiddenno
parent revision#88426d482415 missing test data file
child revision#51ee3f8f32c7 built-in checkers use [01-50] base message ids (closes #68057)
files modified by this revision
ChangeLog
checkers/variables.py
test/regrtest_data/absimp/__init__.py
test/regrtest_data/absimp/string.py
test/test_regr.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1310128192 -7200
# Fri Jul 08 14:29:52 2011 +0200
# Node ID 2a5477c2a57f31ede1b54644ad94b87a832b8b14
# Parent 88426d4824151426957835ded2badfb6a0d1c8b6
closes #70495: absolute imports fail depending on module path (patch by Jacek Konieczny)

diff --git a/ChangeLog b/ChangeLog
@@ -11,10 +11,13 @@
1        this change may break it has now location gain a new item giving the
2        column offset.
3 
4      * #60828: Fix false positive in reimport check
5 
6 +    * #70495: absolute imports fail depending on module path (patch by Jacek Konieczny)
7 +
8 +
9  2011-01-11  --  0.23.0
10      * documentation update, add manpages
11 
12      * several performance improvements
13 
diff --git a/checkers/variables.py b/checkers/variables.py
@@ -452,12 +452,13 @@
14 
15      @check_messages('E0611')
16      def visit_from(self, node):
17          """check modules attribute accesses"""
18          name_parts = node.modname.split('.')
19 +        level = getattr(node, 'level', None)
20          try:
21 -            module = node.root().import_module(name_parts[0])
22 +            module = node.root().import_module(name_parts[0], level=level)
23          except ASTNGBuildingException:
24              return
25          except Exception, exc:
26              print 'Unhandled exception in VariablesChecker:', exc
27              return
diff --git a/test/regrtest_data/absimp/__init__.py b/test/regrtest_data/absimp/__init__.py
@@ -0,0 +1,5 @@
28 +"""a package with absolute import activated
29 +"""
30 +
31 +from __future__ import absolute_import
32 +
diff --git a/test/regrtest_data/absimp/string.py b/test/regrtest_data/absimp/string.py
@@ -0,0 +1,7 @@
33 +"""
34 +http://www.logilab.org/ticket/70495
35 +http://www.logilab.org/ticket/70565
36 +"""
37 +from __future__ import absolute_import
38 +import string
39 +print string
diff --git a/test/test_regr.py b/test/test_regr.py
@@ -137,14 +137,17 @@
40                  linter.reporter.finalize().strip()
41 
42      def test_try_finally_disable_msg_crash(self):
43          linter.check(join(REGR_DATA, 'try_finally_disable_msg_crash'))
44 
45 -
46      def test___path__(self):
47          linter.check('pylint.checkers.__init__')
48          messages = linter.reporter.finalize().strip()
49          self.failIf('__path__' in messages, messages)
50 
51 +    def test_absolute_import(self):
52 +        linter.check(join(REGR_DATA, 'absimp', 'string.py'))
53 +        got = linter.reporter.finalize().strip()
54 +        self.failUnlessEqual(got, "W:  6: Uses of a deprecated module 'string'")
55 
56  if __name__ == '__main__':
57      unittest_main()