Skip to content

Change exec_module to load_module#2249

Merged
jaraco merged 2 commits into
pypa:masterfrom
alexhenrie:imp
Jul 12, 2020
Merged

Change exec_module to load_module#2249
jaraco merged 2 commits into
pypa:masterfrom
alexhenrie:imp

Conversation

@alexhenrie

Copy link
Copy Markdown
Contributor

I originally wrote this code using load_module and then changed it to exec_module because the documentation says that load_module is deprecated, but I didn't notice that exec_module requires an argument. Since it's not clear from the documentation how exec_module is supposed to be used, and load_module doesn't actually emit a DeprecationWarning (fixing the warning was the original motivation for changing this code), I think we should just use load_module for now.

@hugovk

hugovk commented Jul 11, 2020

Copy link
Copy Markdown
Contributor

Thanks for the quick update!

Is it possible to include tests for this code?

And do you have an idea why we only hit this on Python 3.9 and not 3.5-3.8?

@alexhenrie

Copy link
Copy Markdown
Contributor Author

@hugovk Unfortunately, I don't know the answer to either of those questions.

@jaraco jaraco merged commit 8b45da0 into pypa:master Jul 12, 2020
@pangloss

Copy link
Copy Markdown

This issue hit me today on both 3.7.5 and 3.7.7.

@grlee77

grlee77 commented Jul 14, 2020

Copy link
Copy Markdown

Since it's not clear from the documentation how exec_module is supposed to be used, and load_module doesn't actually emit a DeprecationWarning (fixing the warning was the original motivation for changing this code), I think we should just use load_module for now.

By strange coincidence, I just happened to be looking at this same load_module vs exec_module usage for our setup.py in PyWavelets. I think in your case, the code would be something like the following (untested, adapated from an answer in this stack overflow post):

 import types
 from importlib.machinery import ExtensionFileLoader
 loader = ExtensionFileLoader(__name__, __file__)
 module = types.ModuleType(loader.name)
 loader.exec_module(module)

@danielgordon10

Copy link
Copy Markdown

Can you please push a patch to PYPI? Many projects that don't pin the version are starting to get the bug.

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.

6 participants