Commits

Sylvain Thénault committed 2a5477c

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

  • Participants
  • Parent commits 88426d4

Comments (0)

Files changed (5)

 
     * #60828: Fix false positive in reimport check
 
+    * #70495: absolute imports fail depending on module path (patch by Jacek Konieczny)
+
+
 2011-01-11  --  0.23.0
     * documentation update, add manpages
 

checkers/variables.py

     def visit_from(self, node):
         """check modules attribute accesses"""
         name_parts = node.modname.split('.')
+        level = getattr(node, 'level', None)
         try:
-            module = node.root().import_module(name_parts[0])
+            module = node.root().import_module(name_parts[0], level=level)
         except ASTNGBuildingException:
             return
         except Exception, exc:

test/regrtest_data/absimp/__init__.py

+"""a package with absolute import activated
+"""
+
+from __future__ import absolute_import
+

test/regrtest_data/absimp/string.py

+"""
+http://www.logilab.org/ticket/70495
+http://www.logilab.org/ticket/70565
+"""
+from __future__ import absolute_import
+import string
+print string

test/test_regr.py

     def test_try_finally_disable_msg_crash(self):
         linter.check(join(REGR_DATA, 'try_finally_disable_msg_crash'))
 
-
     def test___path__(self):
         linter.check('pylint.checkers.__init__')
         messages = linter.reporter.finalize().strip()
         self.failIf('__path__' in messages, messages)
 
+    def test_absolute_import(self):
+        linter.check(join(REGR_DATA, 'absimp', 'string.py'))
+        got = linter.reporter.finalize().strip()
+        self.failUnlessEqual(got, "W:  6: Uses of a deprecated module 'string'")
 
 if __name__ == '__main__':
     unittest_main()