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

The frozen importer should capture info in find_spec(). #89487

Closed
ericsnowcurrently opened this issue Sep 29, 2021 · 3 comments
Closed

The frozen importer should capture info in find_spec(). #89487

ericsnowcurrently opened this issue Sep 29, 2021 · 3 comments
Assignees
Labels
3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ericsnowcurrently
Copy link
Member

BPO 45324
Nosy @warsaw, @ericsnowcurrently
PRs
  • bpo-45324: Capture data in FrozenImporter.find_spec() to use in exec_module(). #28633
  • bpo-45324: Rearrange some of the FrozenImporter finder tests. #28740
  • 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/ericsnowcurrently'
    closed_at = <Date 2021-10-05.16:02:33.592>
    created_at = <Date 2021-09-29.17:57:04.035>
    labels = ['interpreter-core', 'type-bug', '3.11']
    title = 'The frozen importer should capture info in find_spec().'
    updated_at = <Date 2021-10-05.16:09:57.175>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2021-10-05.16:09:57.175>
    actor = 'eric.snow'
    assignee = 'eric.snow'
    closed = True
    closed_date = <Date 2021-10-05.16:02:33.592>
    closer = 'eric.snow'
    components = ['Interpreter Core']
    creation = <Date 2021-09-29.17:57:04.035>
    creator = 'eric.snow'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45324
    keywords = ['patch']
    message_count = 3.0
    messages = ['402895', '402896', '403247']
    nosy_count = 2.0
    nosy_names = ['barry', 'eric.snow']
    pr_nums = ['28633', '28740']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45324'
    versions = ['Python 3.11']

    @ericsnowcurrently
    Copy link
    Member Author

    Currently FrozenImporter (in Lib/importlib/_bootstrap.py) does minimal work in its find_spec() method. It only checks whether or not the module is frozen. However, in doing so it has gathered all the info we need to load the module. We end up repeating that work in exec_module().

    Rather than duplicating that effort, we should preserve the info in spec.loader_state. This has the added benefit of aligning more closely with the division between finder and loader. Once we get to the loader, there shouldn't be a need to check if the module is frozen nor otherwise interact with the internal frozen module state (i.e. PyImport_FrozenModules).

    @ericsnowcurrently ericsnowcurrently added the 3.11 only security fixes label Sep 29, 2021
    @ericsnowcurrently ericsnowcurrently self-assigned this Sep 29, 2021
    @ericsnowcurrently ericsnowcurrently added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error 3.11 only security fixes labels Sep 29, 2021
    @ericsnowcurrently ericsnowcurrently self-assigned this Sep 29, 2021
    @ericsnowcurrently ericsnowcurrently added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Sep 29, 2021
    @ericsnowcurrently
    Copy link
    Member Author

    Taking care of this will also be necessary (probably) as we work on adding __file__ to frozen stdlib modules. (See bpo-21736.)

    @ericsnowcurrently
    Copy link
    Member Author

    New changeset c3d9ac8 by Eric Snow in branch 'main':
    bpo-45324: Capture data in FrozenImporter.find_spec() to use in exec_module(). (gh-28633)
    c3d9ac8

    @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.11 only security fixes 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

    1 participant