Commit ab9b31f9 authored by Anthony Sottile's avatar Anthony Sottile Committed by Miss Islington (bot)

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

parent 8a1bab92
......@@ -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
......
......@@ -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()
Implement ``__getitem__`` for ``_NamespacePath``. Patch by Anthony Sottile.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment