Skip to content

Commit ab9b31f

Browse files
asottilemiss-islington
authored andcommitted
bpo-35843: Implement __getitem__ for _NamespacePath (GH-11690)
1 parent 8a1bab9 commit ab9b31f

File tree

4 files changed

+888
-869
lines changed

4 files changed

+888
-869
lines changed

Lib/importlib/_bootstrap_external.py

+3
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,9 @@ def _recalculate(self):
11631163
def __iter__(self):
11641164
return iter(self._recalculate())
11651165

1166+
def __getitem__(self, index):
1167+
return self._recalculate()[index]
1168+
11661169
def __setitem__(self, index, path):
11671170
self._path[index] = path
11681171

Lib/test/test_importlib/test_namespace_pkgs.py

+6
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ def test_namespace_origin_consistency(self):
332332
self.assertIsNone(foo.__spec__.origin)
333333
self.assertIsNone(foo.__file__)
334334

335+
def test_path_indexable(self):
336+
# bpo-35843
337+
import foo
338+
expected_path = os.path.join(self.root, 'portion1', 'foo')
339+
self.assertEqual(foo.__path__[0], expected_path)
340+
335341

336342
if __name__ == "__main__":
337343
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement ``__getitem__`` for ``_NamespacePath``. Patch by Anthony Sottile.

0 commit comments

Comments
 (0)