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

Get rid of load_module from import hooks #222

Merged
merged 3 commits into from
Nov 18, 2024

Conversation

peterebden
Copy link
Contributor

Turns out this has been deprecated since 3.4 (!), when you run it with a sufficiently debug Python it issues DeprecationWarnings about it.

Change to use create_module and exec_module which are the more modern way.

import unittest


class TestModuleDirImport(unittest.TestCase):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weirdly we didn't seem to have anything that tested this sufficiently directly - I would have thought we must have but I got ModuleDirImport through them all with a deliberately busted implementation of exec_module...

"""Actually load a module that we said we'd handle in find_module."""
module = import_module(fullname[len(self.prefix):])
sys.modules[fullname] = module
module = import_module(spec.name[len(self.prefix):])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe this is mildly not nice (it kind of does everything in create_module and leaves nothing for exec_module) but I can't find a convenient equivalent to break it into the two parts.

@peterebden peterebden merged commit 0452499 into please-build:master Nov 18, 2024
12 checks passed
@peterebden peterebden deleted the get-rid-of-load-module branch November 18, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants