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

fix imp python module for versions higher than 3.4 #1904

Closed
wants to merge 2 commits into from

Conversation

NarineM
Copy link
Contributor

@NarineM NarineM commented Mar 21, 2024

Based on https://docs.python.org/3.6/library/imp.html imp has been deprecated starting python version 3.4

@NarineM NarineM requested review from D1v38om83r, nkuchta and a team as code owners March 21, 2024 23:54
@NarineM NarineM changed the title fix imp python module for versions higher than 3.6 fix imp python module for versions higher than 3.4 Mar 21, 2024
@NarineM
Copy link
Contributor Author

NarineM commented Mar 25, 2024

Not able to repro on python 3.6, Can run import imp on python 3.4 as well as with python 3.6. Putting this change on hold (not needed). The module was replacedwith importlib but it is still present in 3.4/3.6. We ll need to revisit this code to take this fix in the future if it is removed from newer versions of python

@matthew-rollitt
Copy link

This isn't enough https://docs.python.org/dev/whatsnew/3.12.html#imp

on line 54 you also need to do this

import importlib.util
import importlib.machinery

def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.name] = module
loader.exec_module(module)
return module

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