Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importlib.util docs for namespace packages innaccurate #80024

Closed
asottile mannequin opened this issue Jan 28, 2019 · 6 comments
Closed

importlib.util docs for namespace packages innaccurate #80024

asottile mannequin opened this issue Jan 28, 2019 · 6 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes docs Documentation in the Doc dir

Comments

@asottile
Copy link
Mannequin

asottile mannequin commented Jan 28, 2019

BPO 35843
Nosy @warsaw, @brettcannon, @ronaldoussoren, @ncoghlan, @ericvsmith, @ericsnowcurrently, @asottile, @miss-islington
PRs
  • bpo-35843: Implement __getitem__ for _NamespacePath #11690
  • bpo-35843: Implement __getitem__ for _NamespacePath #11690
  • bpo-35843: Implement __getitem__ for _NamespacePath #11690
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-03-08.18:58:36.684>
    created_at = <Date 2019-01-28.18:03:10.897>
    labels = ['3.7', '3.8', 'docs']
    title = 'importlib.util docs for namespace packages innaccurate'
    updated_at = <Date 2019-03-08.18:58:36.683>
    user = 'https://github.com/asottile'

    bugs.python.org fields:

    activity = <Date 2019-03-08.18:58:36.683>
    actor = 'brett.cannon'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2019-03-08.18:58:36.684>
    closer = 'brett.cannon'
    components = ['Documentation']
    creation = <Date 2019-01-28.18:03:10.897>
    creator = 'Anthony Sottile'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35843
    keywords = ['patch', 'patch', 'patch']
    message_count = 6.0
    messages = ['334484', '334485', '334506', '336954', '337050', '337524']
    nosy_count = 9.0
    nosy_names = ['barry', 'brett.cannon', 'ronaldoussoren', 'ncoghlan', 'eric.smith', 'docs@python', 'eric.snow', 'Anthony Sottile', 'miss-islington']
    pr_nums = ['11690', '11690', '11690']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue35843'
    versions = ['Python 3.7', 'Python 3.8']

    @asottile
    Copy link
    Mannequin Author

    asottile mannequin commented Jan 28, 2019

    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

    @asottile asottile mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Jan 28, 2019
    @asottile asottile mannequin assigned docspython Jan 28, 2019
    @asottile asottile mannequin added the docs Documentation in the Doc dir label Jan 28, 2019
    @asottile
    Copy link
    Mannequin Author

    asottile mannequin commented Jan 28, 2019

    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

    @ronaldoussoren
    Copy link
    Contributor

    See also bpo-35673.

    @brettcannon
    Copy link
    Member

    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.

    @warsaw
    Copy link
    Member

    warsaw commented Mar 3, 2019

    +1

    @miss-islington
    Copy link
    Contributor

    New changeset ab9b31f by Miss Islington (bot) (Anthony Sottile) in branch 'master':
    bpo-35843: Implement __getitem__ for _NamespacePath (GH-11690)
    ab9b31f

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants