Browse Source

bpo-35843: Implement __getitem__ for _NamespacePath (GH-11690)

pull/12243/head
Anthony Sottile 7 years ago
committed by Miss Islington (bot)
parent
commit
ab9b31f947
  1. 3
      Lib/importlib/_bootstrap_external.py
  2. 6
      Lib/test/test_importlib/test_namespace_pkgs.py
  3. 1
      Misc/NEWS.d/next/Library/2019-01-28-10-19-40.bpo-35843.7rXGQE.rst
  4. 1747
      Python/importlib_external.h

3
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

6
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()

1
Misc/NEWS.d/next/Library/2019-01-28-10-19-40.bpo-35843.7rXGQE.rst

@ -0,0 +1 @@
Implement ``__getitem__`` for ``_NamespacePath``. Patch by Anthony Sottile.

1747
Python/importlib_external.h
File diff suppressed because it is too large
View File

Loading…
Cancel
Save