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

pkgutil.get_loader() fails on "__main__" #65399

Closed
ericsnowcurrently opened this issue Apr 11, 2014 · 5 comments
Closed

pkgutil.get_loader() fails on "__main__" #65399

ericsnowcurrently opened this issue Apr 11, 2014 · 5 comments
Labels
release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ericsnowcurrently
Copy link
Member

BPO 21200
Nosy @brettcannon, @ncoghlan, @larryhastings, @ericsnowcurrently
Files
  • issue21200-pkgutil-main.diff
  • 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 2014-04-19.06:20:35.397>
    created_at = <Date 2014-04-11.14:07:35.554>
    labels = ['type-bug', 'library', 'release-blocker']
    title = 'pkgutil.get_loader() fails on "__main__"'
    updated_at = <Date 2014-04-19.06:20:35.395>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2014-04-19.06:20:35.395>
    actor = 'eric.snow'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-04-19.06:20:35.397>
    closer = 'eric.snow'
    components = ['Library (Lib)']
    creation = <Date 2014-04-11.14:07:35.554>
    creator = 'eric.snow'
    dependencies = []
    files = ['34808']
    hgrepos = []
    issue_num = 21200
    keywords = ['patch', '3.4regression']
    message_count = 5.0
    messages = ['215926', '216043', '216048', '216847', '216848']
    nosy_count = 5.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'larry', 'python-dev', 'eric.snow']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21200'
    versions = ['Python 3.4', 'Python 3.5']

    @ericsnowcurrently
    Copy link
    Member Author

    Prior to 3.4, pkgutil.get_loader('__main__') would return None. Now it results in an ImportError. That's because it calls importlib.util.find_spec() which fails if an existing module does not have __spec__ or it is None.

    @ericsnowcurrently ericsnowcurrently added release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 11, 2014
    @ericsnowcurrently
    Copy link
    Member Author

    Here's a patch that checks for modules that don't have __spec__ set.

    The patch will fix the problem. However note that the docs and docstring imply (to me) that we should turn any ImportError coming out of the find_loader() call into returning None. Fixing that will also fix this bug, so this patch may be unnecessary.

    @ericsnowcurrently
    Copy link
    Member Author

    I've opened bpo-21211 to more directly address the find_loader() issue.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 19, 2014

    New changeset bc4eb1b3db5d by Eric Snow in branch '3.4':
    Issue bpo-21200: Return None from pkgutil.get_loader() when __spec__ is missing.
    http://hg.python.org/cpython/rev/bc4eb1b3db5d

    @ericsnowcurrently
    Copy link
    Member Author

    The change is pretty minor so I went ahead and pushed it. To be honest, we should consider deprecating both get_loader and find_loader. I'm just not going to worry about it right now. :)

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

    No branches or pull requests

    1 participant