Skip to content

MNT: do not use deprecated load_module method#218

Merged
uglide merged 2 commits intoredis:masterfrom
tacaswell:fix/py315_compat
Jan 30, 2026
Merged

MNT: do not use deprecated load_module method#218
uglide merged 2 commits intoredis:masterfrom
tacaswell:fix/py315_compat

Conversation

@tacaswell
Copy link
Contributor

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

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
@jit-ci
Copy link

jit-ci bot commented Jan 1, 2026

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 in setup.py with runpy.run_path(...).
  • Remove the importlib import and add runpy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@uglide uglide left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@uglide uglide merged commit 475d682 into redis:master Jan 30, 2026
39 checks passed
@tacaswell tacaswell deleted the fix/py315_compat branch January 30, 2026 15:59
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