summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-05-08 16:30:02 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2016-05-09 17:40:06 +0300
commit5c1c00bfa28eb71677d2561689a919d9ebce6fd1 (patch)
tree34365996602ff5ace529a4163e3e09179464cbb5
parentfdd911c08fd1b6f4a19ec270d8a87f72a8b2f7d1 (diff)
downloadastroid-git-5c1c00bfa28eb71677d2561689a919d9ebce6fd1.tar.gz
Don't introduce empty values for non-zip importers in path_importer_cache and add a test for implicit namespace packages.
-rw-r--r--astroid/modutils.py4
-rw-r--r--astroid/tests/testdata/python2/data/namespace_pep_420/module.py0
-rw-r--r--astroid/tests/testdata/python3/data/namespace_pep_420/module.py0
-rw-r--r--astroid/tests/unittest_manager.py11
4 files changed, 13 insertions, 2 deletions
diff --git a/astroid/modutils.py b/astroid/modutils.py
index abc89814..8b45d4f5 100644
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -652,7 +652,7 @@ def _precache_zipimporters(path=None):
try:
pic[entry_path] = zipimport.zipimporter(entry_path)
except zipimport.ZipImportError:
- pic[entry_path] = None
+ continue
return pic
@@ -805,7 +805,7 @@ def _find_spec(modpath, path=None):
# Need a copy for not mutating the argument.
modpath = modpath[:]
- submodule_path = []
+ submodule_path = None
module_parts = modpath[:]
processed = []
diff --git a/astroid/tests/testdata/python2/data/namespace_pep_420/module.py b/astroid/tests/testdata/python2/data/namespace_pep_420/module.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/astroid/tests/testdata/python2/data/namespace_pep_420/module.py
diff --git a/astroid/tests/testdata/python3/data/namespace_pep_420/module.py b/astroid/tests/testdata/python3/data/namespace_pep_420/module.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/astroid/tests/testdata/python3/data/namespace_pep_420/module.py
diff --git a/astroid/tests/unittest_manager.py b/astroid/tests/unittest_manager.py
index 9c74b78f..abf1d32c 100644
--- a/astroid/tests/unittest_manager.py
+++ b/astroid/tests/unittest_manager.py
@@ -113,6 +113,17 @@ class AstroidManagerTest(resources.SysPathSetup,
def test_ast_from_namespace_pkg_resources(self):
self._test_ast_from_old_namespace_package_protocol('pkg_resources')
+ @unittest.skipUnless(sys.version_info[:2] > (3, 3), "Needs PEP 420 namespace protocol")
+ def test_implicit_namespace_package(self):
+ data_dir = os.path.abspath(os.path.join(resources.DATA_DIR, 'data'))
+ sys.path.insert(0, data_dir)
+ try:
+ module = self.manager.ast_from_module_name('namespace_pep_420.module')
+ self.assertIsInstance(module, astroid.Module)
+ self.assertEqual(module.name, 'namespace_pep_420.module')
+ finally:
+ sys.path.pop(0)
+
def _test_ast_from_zip(self, archive):
origpath = sys.path[:]
sys.modules.pop('mypypa', None)