Issue35843
Created on 2019-01-28 18:03 by Anthony Sottile, last changed 2019-03-08 18:58 by brett.cannon. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 11690 | merged | Anthony Sottile, 2019-01-28 18:23 | |
| PR 11690 | merged | Anthony Sottile, 2019-01-28 18:24 | |
| PR 11690 | merged | Anthony Sottile, 2019-01-28 18:24 | |
| Messages (6) | |||
|---|---|---|---|
| msg334484 - (view) | Author: Anthony Sottile (Anthony Sottile) * | Date: 2019-01-28 18:03 | |
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 |
|||
| msg334485 - (view) | Author: Anthony Sottile (Anthony Sottile) * | Date: 2019-01-28 18:07 | |
Hmmm, it appears this was changed in python3.7 to have `None` for the origin instead of `'namespace'` -- however the `submodule_search_locations` is still not indexable:
>>> importlib.util.find_spec('a')
ModuleSpec(name='a', loader=None, submodule_search_locations=_NamespacePath(['/tmp/x/a']))
>>> importlib.util.find_spec('a').origin
>>> spec = importlib.util.find_spec('a')
>>> spec.submodule_search_locations
_NamespacePath(['/tmp/x/a'])
>>> spec.submodule_search_locations[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '_NamespacePath' object does not support indexing
|
|||
| msg334506 - (view) | Author: Ronald Oussoren (ronaldoussoren) * | Date: 2019-01-29 09:10 | |
See also #35673. |
|||
| msg336954 - (view) | Author: Brett Cannon (brett.cannon) * | Date: 2019-03-01 20:36 | |
Anyone have an opinion about the __getitem__ proposal? I'm fine with it but I wanted to make sure other import + namespace folks don't disagree. |
|||
| msg337050 - (view) | Author: Barry A. Warsaw (barry) * | Date: 2019-03-03 23:24 | |
+1 |
|||
| msg337524 - (view) | Author: miss-islington (miss-islington) | Date: 2019-03-08 18:58 | |
New changeset ab9b31f94737895f0121f26ba3ad718ebbc24fe1 by Miss Islington (bot) (Anthony Sottile) in branch 'master': bpo-35843: Implement __getitem__ for _NamespacePath (GH-11690) https://github.com/python/cpython/commit/ab9b31f94737895f0121f26ba3ad718ebbc24fe1 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2019-03-08 18:58:36 | brett.cannon | set | keywords:
patch, patch, patch status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-03-08 18:58:19 | miss-islington | set | nosy:
+ miss-islington messages: + msg337524 |
| 2019-03-03 23:24:07 | barry | set | keywords:
patch, patch, patch messages: + msg337050 |
| 2019-03-01 20:36:54 | brett.cannon | set | keywords:
patch, patch, patch messages: + msg336954 |
| 2019-02-14 20:51:11 | brett.cannon | set | keywords:
patch, patch, patch nosy: + barry, ncoghlan, eric.smith, eric.snow |
| 2019-01-29 09:10:02 | ronaldoussoren | set | keywords:
patch, patch, patch nosy: + ronaldoussoren messages: + msg334506 |
| 2019-01-28 19:32:39 | xtreak | set | keywords:
patch, patch, patch nosy: + brett.cannon |
| 2019-01-28 18:24:09 | Anthony Sottile | set | keywords:
+ patch stage: patch review pull_requests: + pull_request11531 |
| 2019-01-28 18:24:03 | Anthony Sottile | set | keywords:
+ patch stage: (no value) pull_requests: + pull_request11530 |
| 2019-01-28 18:23:58 | Anthony Sottile | set | keywords:
+ patch stage: (no value) pull_requests: + pull_request11529 |
| 2019-01-28 18:07:26 | Anthony Sottile | set | messages: + msg334485 |
| 2019-01-28 18:03:10 | Anthony Sottile | create | |