This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Anthony Sottile
Recipients Anthony Sottile, docs@python
Date 2019-01-28.18:03:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1548698590.94.0.426601552573.issue35843@roundup.psfhosted.org>
In-reply-to
Content
For instance:


# `a` is an empty directory, a PEP 420 namespace package

>>> import importlib.util
>>> importlib.util.find_spec('a')
ModuleSpec(name='a', loader=None, origin='namespace', submodule_search_locations=_NamespacePath(['/tmp/x/a']))


https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec.origin

> ...  Normally “origin” should be set, but it may be None (the default) which indicates it is unspecified (e.g. for namespace packages).

above the `origin` is `'namespace'`

https://docs.python.org/3/library/importlib.html#importlib.machinery.ModuleSpec.submodule_search_locations

> List of strings for where to find submodules, if a package (None otherwise).

However the `_NamespacePath` object above is not indexable:

>>> x = importlib.util.find_spec('a').submodule_search_locations
>>> x[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: '_NamespacePath' object does not support indexing


I can work around however with:

>>> next(iter(x))
'/tmp/x/a'


======================


so I guess a few things can/should come out of this:

- Document the `'namespace'` origin
- Document that `submodule_search_paths` is a Sized[str] instead
- Add `__getitem__` to `_NamespacePath` such that it implements the full `Sized` protocol
History
Date User Action Args
2019-01-28 18:03:13Anthony Sottilesetrecipients: + Anthony Sottile, docs@python
2019-01-28 18:03:10Anthony Sottilesetmessageid: <1548698590.94.0.426601552573.issue35843@roundup.psfhosted.org>
2019-01-28 18:03:10Anthony Sottilelinkissue35843 messages
2019-01-28 18:03:10Anthony Sottilecreate