forked from VimPlug/jedi
Don't assume every module has a namespace
This commit is contained in:
@@ -333,6 +333,9 @@ def _enables_absolute_import(imp):
|
|||||||
Checks if the import is a ``__future__`` import that enables the
|
Checks if the import is a ``__future__`` import that enables the
|
||||||
``absolute_import`` feature.
|
``absolute_import`` feature.
|
||||||
"""
|
"""
|
||||||
|
if imp.namespace is None:
|
||||||
|
return False
|
||||||
|
|
||||||
namespace, feature = imp.from_ns.names[0], imp.namespace.names[0]
|
namespace, feature = imp.from_ns.names[0], imp.namespace.names[0]
|
||||||
return namespace == "__future__" and feature == "absolute_import"
|
return namespace == "__future__" and feature == "absolute_import"
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,16 @@ def test_py2_imports_are_not_always_absolute():
|
|||||||
assert not parser.scope.absolute_imports
|
assert not parser.scope.absolute_imports
|
||||||
|
|
||||||
|
|
||||||
|
def test_dont_break_imports_without_namespaces():
|
||||||
|
"""
|
||||||
|
The code checking for ``from __future__ import absolute_import`` shouldn't
|
||||||
|
assume that all imports have non-``None`` ``namespace`` attributes.
|
||||||
|
"""
|
||||||
|
src = "from __future__ import absolute_import\nimport xyzzy"
|
||||||
|
parser = Parser(src, "test.py")
|
||||||
|
assert parser.scope.absolute_imports
|
||||||
|
|
||||||
|
|
||||||
def test_imports_are_absolute_in_modules_with_future_import():
|
def test_imports_are_absolute_in_modules_with_future_import():
|
||||||
"""
|
"""
|
||||||
In any module with the ``absolute_import`` ``__future__`` import, all
|
In any module with the ``absolute_import`` ``__future__`` import, all
|
||||||
|
|||||||
Reference in New Issue
Block a user