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

Have importlib.resources.contents() return an interable instead of an iterator #77435

Closed
brettcannon opened this issue Apr 10, 2018 · 5 comments
Assignees
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@brettcannon
Copy link
Member

BPO 33254
Nosy @warsaw, @brettcannon, @miss-islington
PRs
  • bpo-33254: do not return an empty list when asking for the contents of a namespace package #6467
  • [3.7] bpo-33254: do not return an empty list when asking for the contents of a namespace package (GH-6467) #6664
  • 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 = 'https://github.com/brettcannon'
    closed_at = <Date 2018-04-30.19:44:12.799>
    created_at = <Date 2018-04-10.00:27:02.060>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'Have importlib.resources.contents() return an interable instead of an iterator'
    updated_at = <Date 2018-04-30.19:44:12.799>
    user = 'https://github.com/brettcannon'

    bugs.python.org fields:

    activity = <Date 2018-04-30.19:44:12.799>
    actor = 'brett.cannon'
    assignee = 'brett.cannon'
    closed = True
    closed_date = <Date 2018-04-30.19:44:12.799>
    closer = 'brett.cannon'
    components = ['Library (Lib)']
    creation = <Date 2018-04-10.00:27:02.060>
    creator = 'brett.cannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33254
    keywords = ['patch']
    message_count = 5.0
    messages = ['315155', '315156', '315170', '315959', '315961']
    nosy_count = 3.0
    nosy_names = ['barry', 'brett.cannon', 'miss-islington']
    pr_nums = ['6467', '6664']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33254'
    versions = ['Python 3.7', 'Python 3.8']

    @brettcannon
    Copy link
    Member Author

    If you look at

    you will notice that the generator for importlib.resources.contents() return an empty list. While the intent was to have no values be returned by contents(), by virtue of being a generator that empty list is actually being returned as a value.

    @brettcannon brettcannon added 3.7 (EOL) end of life 3.8 only security fixes labels Apr 10, 2018
    @brettcannon brettcannon self-assigned this Apr 10, 2018
    @brettcannon brettcannon added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 10, 2018
    @warsaw
    Copy link
    Member

    warsaw commented Apr 10, 2018

    Note that this is in the case where a user is asking for the contents of a namespace package (which by definition, can't have resources).

    +1 on fixing this API wart.

    Will you @brett.cannon will submit a PR? I'll do a quick review and then backport the change to the standalone library.

    @brettcannon
    Copy link
    Member Author

    I had to stare at it for a while since I knew it was for namespace packages and I'm so used to them returning a magical value to signal that fact, but then realize we don't even support namespace packages so it wasn't magical at all. ;)

    And yes, I'll do a PR and make you a reviewer probably this Friday.

    @brettcannon brettcannon changed the title importlib.resources.contents() incorrectly yields an empty list Have importlib.resources.contents() return an interable instead of an iterator Apr 20, 2018
    @brettcannon
    Copy link
    Member Author

    New changeset 3ab9365 by Brett Cannon in branch 'master':
    bpo-33254: do not return an empty list when asking for the contents of a namespace package (GH-6467)
    3ab9365

    @miss-islington
    Copy link
    Contributor

    New changeset 2e5fa38 by Miss Islington (bot) in branch '3.7':
    bpo-33254: do not return an empty list when asking for the contents of a namespace package (GH-6467)
    2e5fa38

    @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 stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants