diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | astroid/mixins.py | 3 | ||||
-rw-r--r-- | astroid/tests/unittest_inference.py | 9 |
3 files changed, 8 insertions, 10 deletions
@@ -228,6 +228,12 @@ Change log for the astroid package (used to be astng) an astroid AST from a source code string, similar to how ast.parse can be used to obtain a Python AST from a source string. This is the test_utils.build_module promoted to a public API. + + * do_import_module passes the proper relative_only flag if the level is higher + than 1. This has the side effect that using `from .something import something` + in a non-package will finally result in an import-error on Pylint's side. + Until now relative_only was ignored, leading to the import of `something`, + if it was globally available. diff --git a/astroid/mixins.py b/astroid/mixins.py index 6edccfbe..d374a49f 100644 --- a/astroid/mixins.py +++ b/astroid/mixins.py @@ -125,7 +125,8 @@ class ImportFromMixin(FilterStmtsMixin): # FIXME: we used to raise InferenceError here, but why ? return mymodule try: - return mymodule.import_module(modname, level=level) + return mymodule.import_module(modname, level=level, + relative_only=level and level >= 1) except AstroidBuildingException as ex: if isinstance(ex.args[0], SyntaxError): raise InferenceError(str(ex)) diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py index beb85e47..4674e92b 100644 --- a/astroid/tests/unittest_inference.py +++ b/astroid/tests/unittest_inference.py @@ -1098,15 +1098,6 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): "ignored") self.assertNotIn("RuntimeError", output, msg) - def test_python25_relative_import(self): - data = "from ...logilab.common import date; print (date)" - # !! FIXME also this relative import would not work 'in real' (no __init__.py in test/) - # the test works since we pretend we have a package by passing the full modname - ast = builder.string_build(data, 'astroid.test.unittest_inference', __file__) - inferred = next(test_utils.get_name_node(ast, 'date').infer()) - self.assertIsInstance(inferred, nodes.Module) - self.assertEqual(inferred.name, 'logilab.common.date') - def test_python25_no_relative_import(self): ast = resources.build_file('data/package/absimport.py') self.assertTrue(ast.absolute_import_activated(), True) |