MNT: do not use deprecated load_module method#218
Conversation
The load_module method has been deprecated from py34 and will be removed in py315 [1] (it is already gone on CPython main). The recommended replacement is exec_module, however the documentation [2] suggests to use a simpler approach than using the loaders directly and runpy [3] seemed better than sys.path hacking. Given that this is a one-line file simply reading the file and parsing it 'by hand' is an option. [1] https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module [2] https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly [3] https://docs.python.org/3/library/runpy.html#runpy.run_path
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
There was a problem hiding this comment.
Pull request overview
Updates packaging/version retrieval to avoid importlib’s deprecated Loader.load_module() (removed on CPython main and slated for removal in Python 3.15), switching to a supported mechanism.
Changes:
- Replace
importlib.machinery.SourceFileLoader(...).load_module()usage insetup.pywithrunpy.run_path(...). - Remove the
importlibimport and addrunpy.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
uglide
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
The load_module method has been deprecated from py34 and will be removed in py315 [1] (it is already gone on CPython main). The recommended replacement is exec_module, however the documentation [2] suggests to use a simpler approach than using the loaders directly and runpy [3] seemed better than sys.path hacking. Given that this is a one-line file simply reading the file and parsing it 'by hand' is an option. [1] https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module [2] https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly [3] https://docs.python.org/3/library/runpy.html#runpy.run_path Co-authored-by: Igor Malinovskiy <[email protected]> (cherry picked from commit 475d682)
The load_module method has been deprecated from py34 and will be removed in py315 [1] (it is already gone on CPython main).
The recommended replacement is exec_module, however the documentation [2] suggests to use a simpler approach than using the loaders directly and runpy [3] seemed better than sys.path hacking.
Given that this is a one-line file simply reading the file and parsing it 'by hand' is an option.
[1] https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module
[2] https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
[3] https://docs.python.org/3/library/runpy.html#runpy.run_path