diff options
author | Anthony Sottile <asottile@umich.edu> | 2019-03-08 18:58:00 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-03-08 18:58:00 (GMT) |
commit | ab9b31f94737895f0121f26ba3ad718ebbc24fe1 (patch) | |
tree | 5891d2056a0f382f4f3a53a24a8d2b97069f8186 /Lib | |
parent | 8a1bab92915dd5c88832706c56af2f5611181d50 (diff) | |
download | cpython-ab9b31f94737895f0121f26ba3ad718ebbc24fe1.zip cpython-ab9b31f94737895f0121f26ba3ad718ebbc24fe1.tar.gz cpython-ab9b31f94737895f0121f26ba3ad718ebbc24fe1.tar.bz2 |
bpo-35843: Implement __getitem__ for _NamespacePath (GH-11690)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/importlib/_bootstrap_external.py | 3 | ||||
-rw-r--r-- | Lib/test/test_importlib/test_namespace_pkgs.py | 6 |
2 files changed, 9 insertions, 0 deletions
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 71fdd0c..146c647 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -1163,6 +1163,9 @@ class _NamespacePath: def __iter__(self): return iter(self._recalculate()) + def __getitem__(self, index): + return self._recalculate()[index] + def __setitem__(self, index, path): self._path[index] = path diff --git a/Lib/test/test_importlib/test_namespace_pkgs.py b/Lib/test/test_importlib/test_namespace_pkgs.py index 8e4b5d6..a8f95a0 100644 --- a/Lib/test/test_importlib/test_namespace_pkgs.py +++ b/Lib/test/test_importlib/test_namespace_pkgs.py @@ -332,6 +332,12 @@ class LoaderTests(NamespacePackageTest): self.assertIsNone(foo.__spec__.origin) self.assertIsNone(foo.__file__) + def test_path_indexable(self): + # bpo-35843 + import foo + expected_path = os.path.join(self.root, 'portion1', 'foo') + self.assertEqual(foo.__path__[0], expected_path) + if __name__ == "__main__": unittest.main() |