diff options
| author | Claudiu Popa <pcmanticore@gmail.com> | 2016-05-09 13:12:16 +0300 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-05-09 17:40:07 +0300 |
| commit | cfab7072ce63a207774685782529ba2d6157328d (patch) | |
| tree | 23bbfdfe3ee3f118eae89fe8c64ec0114aee97dd | |
| parent | e31b3e1fe4113ec3867df93272d9d71db1e2b9b6 (diff) | |
| download | astroid-git-cfab7072ce63a207774685782529ba2d6157328d.tar.gz | |
Implicit namespace package support for modpath_from_file for Python 3.3+.
| -rw-r--r-- | astroid/modutils.py | 6 | ||||
| -rw-r--r-- | astroid/tests/unittest_modutils.py | 13 |
2 files changed, 17 insertions, 2 deletions
diff --git a/astroid/modutils.py b/astroid/modutils.py index 28be81f8..5f66eacc 100644 --- a/astroid/modutils.py +++ b/astroid/modutils.py @@ -296,8 +296,10 @@ def _check_init(path, mod_path): for part in mod_path: modpath.append(part) path = os.path.join(path, part) - if not _is_namespace('.'.join(modpath)) and not _has_init(path): - return False + if not _has_init(path): + old_namespace = _is_namespace('.'.join(modpath)) + if not (old_namespace or sys.version_info[:2] > (3, 3)): + return False return True diff --git a/astroid/tests/unittest_modutils.py b/astroid/tests/unittest_modutils.py index 47c418bb..b8d5213c 100644 --- a/astroid/tests/unittest_modutils.py +++ b/astroid/tests/unittest_modutils.py @@ -110,6 +110,19 @@ class ModPathFromFileTest(unittest.TestCase): def test_raise_modpath_from_file_Exception(self): self.assertRaises(Exception, modutils.modpath_from_file, '/turlututu') + def test_modpath_from_file_namespace(self): + datadir = os.path.abspath(resources.find('data')) + path = os.path.abspath( + os.path.join(resources.find('data/namespace_pep_420'), 'module.py') + ) + + sys.path.insert(0, datadir) + try: + modpath = modutils.modpath_from_file(path) + finally: + sys.path.pop(0) + self.assertEqual(modpath, ['namespace_pep_420', 'module']) + class LoadModuleFromPathTest(resources.SysPathSetup, unittest.TestCase): |
