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

_frozen_importlib should not have a __file__ attribute #65141

Closed
ncoghlan opened this issue Mar 16, 2014 · 16 comments
Closed

_frozen_importlib should not have a __file__ attribute #65141

ncoghlan opened this issue Mar 16, 2014 · 16 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ncoghlan
Copy link
Contributor

BPO 20942
Nosy @brettcannon, @ncoghlan, @ericsnowcurrently
Files
  • no_frozen__file__.diff
  • no_frozen__file__.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 = 'https://github.com/brettcannon'
    closed_at = <Date 2014-04-04.14:22:05.901>
    created_at = <Date 2014-03-16.05:42:27.173>
    labels = ['interpreter-core', 'type-bug']
    title = '_frozen_importlib should not have a __file__ attribute'
    updated_at = <Date 2014-04-04.20:22:50.553>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2014-04-04.20:22:50.553>
    actor = 'Arfrever'
    assignee = 'brett.cannon'
    closed = True
    closed_date = <Date 2014-04-04.14:22:05.901>
    closer = 'brett.cannon'
    components = ['Interpreter Core']
    creation = <Date 2014-03-16.05:42:27.173>
    creator = 'ncoghlan'
    dependencies = []
    files = ['34555', '34650']
    hgrepos = []
    issue_num = 20942
    keywords = ['patch']
    message_count = 15.0
    messages = ['213719', '214399', '214926', '215044', '215045', '215046', '215053', '215060', '215061', '215064', '215090', '215122', '215394', '215395', '215524']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'Arfrever', 'python-dev', 'eric.snow', 'Zvezdoslovec']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20942'
    versions = ['Python 3.4', 'Python 3.5']

    @ncoghlan
    Copy link
    Contributor Author

    As part of the PEP-451 changes, frozen imports were updated to avoid setting the __file__ attribute, as that attribute makes no sense for frozen modules.

    However, _frozen_importlib isn't loaded through the normal mechanisms (they don't exist yet!), so it is still getting a __file__ attribute set. (This was discovered while investigating bpo-20884)

    This is a fairly harmless state of affairs, so I suggest we leave it alone in the 3.4 maintenance releases, and just tidy it up in 3.5. However, I'm also open to fixing it in 3.4.1.

    @ncoghlan ncoghlan added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Mar 16, 2014
    @brettcannon
    Copy link
    Member

    Here is a patch to change PyImport_ImportFrozenModuleObject() to not set __file__. Had to refactor some things as PyImport_ExecCodeModuleObject() was setting __file__ no matter what, so to avoid it even being used during import I had to change some things.

    @ericsnowcurrently
    Copy link
    Member

    Review posted.

    @brettcannon
    Copy link
    Member

    New version based on Eric's review.

    @Zvezdoslovec
    Copy link
    Mannequin

    Zvezdoslovec mannequin commented Mar 28, 2014

    This patch can easily be incorporated into Python 3.4.1. It doesn't break backwards compatibility.

    @brettcannon
    Copy link
    Member

    It actually does break backwards-compatibility as an attribute will disappear on frozen modules for anyone who uses the imp API. While the chances of actually breaking someone's code is very small, there is still a chance. But I'm only -0 on backporting so other core devs could convince me that I'm being overly cautious.

    @Zvezdoslovec
    Copy link
    Mannequin

    Zvezdoslovec mannequin commented Mar 28, 2014

    I would say go for it. I don't think anyone's code would break.

    Anyway, if people see that something in the new version of Python breaks their code, they down-grade; otherwise they read the changelog and fix their code accordingly. So no worries here. :)

    @ericsnowcurrently
    Copy link
    Member

    Latest patch LGTM.

    @ericsnowcurrently
    Copy link
    Member

    As I've thought about it, I've gone from -0 to +1 on applying this to both 3.4 and 3.5. The bug and fix should impact very little* code. In fact, I doubt anyone would have noticed if Nick hadn't. :) It would be nice to have this right in 3.4.

    • Effectively this is limited to consumers of imp.init_frozen(), PyImport_ImportFrozenModule(), and PyImport_ImportFrozenModule(). That includes importing frozen importlib and Py_FrozenMain().

    @Zvezdoslovec
    Copy link
    Mannequin

    Zvezdoslovec mannequin commented Mar 28, 2014

    I'm setting Python 3.4 to also be affected by this issue. Thank you, Brett, for making the patch. I hope this gets commited soon.

    @ncoghlan
    Copy link
    Contributor Author

    Yeah, as noted in my original comment, +0 for "it's just a bug" from me, as it was a quirk of the way this particular frozen module is initialised.

    @Zvezdoslovec
    Copy link
    Mannequin

    Zvezdoslovec mannequin commented Mar 29, 2014

    Haven't we forget something in the patch for the docs?

    + .. versionchanged:: 3.5

    •  The ``__file__`` attribute is no longer set on the module.
      

    Where's 3.4 mentioned? Should we add the mention? Like...
    + .. versionchanged:: 3.4

    @Zvezdoslovec
    Copy link
    Mannequin

    Zvezdoslovec mannequin commented Apr 2, 2014

    No one interested in fixing this anymore, despite the patch and all?

    @brettcannon
    Copy link
    Member

    My Python free time is on Fridays, which is when I plan to make a final call and either apply to Python 3.4 and 3.5 or just Python 3.5.

    @brettcannon brettcannon self-assigned this Apr 2, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 4, 2014

    New changeset fef890bd60b1 by Brett Cannon in branch '3.4':
    Issue bpo-20942: PyImport_ImportFrozenModuleObject() no longer sets
    http://hg.python.org/cpython/rev/fef890bd60b1

    New changeset a11ec7aaac10 by Brett Cannon in branch 'default':
    merge of fix for issue bpo-20942
    http://hg.python.org/cpython/rev/a11ec7aaac10

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @1Amankabra
    Copy link

    Import "_frozen_importlib" could not be resolved please help me

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants