Skip to content

Conversation

DJStompZone
Copy link

Fix Module Loading for Compatibility with Python 3.10+

Problem

The thefuck project currently uses the imp module for loading source files dynamically, but this module has been deprecated since Python 3.4 and removed entirely in Python 3.10. As a result, users running Python 3.10+ encounter the following error:

ModuleNotFoundError: No module named 'imp'

Solution

This PR introduces a solution that maintains backward compatibility by replacing imp with importlib.util for Python 3.5+ while providing a fallback to importlib.machinery.SourceFileLoader for Python 3.3 and 3.4. For even older versions, it keeps the final fallback to imp, ensuring compatibility across a wide range of Python versions.

Changes

  • Replaced the imp module import with the following structure:
    • Use importlib.util for Python 3.5+.
    • Use importlib.machinery.SourceFileLoader for Python 3.3 and 3.4.
    • Retain the imp module for Python versions below 3.3.
  • Ensured the changes do not affect existing functionality on older Python versions.

Impact

  • Python 3.10+ users should no longer encounter the ModuleNotFoundError.
  • Existing users on older Python versions should see no changes in behavior.
  • Windows should now be fully compatible

Resolved Issues

This PR closes the following issues:

I'm hoping that's all of them, sorry if I missed any.

@pmcintyre3
Copy link

Can we get this approved? Would love to start using this again.

@simone-05
Copy link

simone-05 commented Nov 14, 2024

Until it gets merged, i just did
pip install https://github.com/DJStompZone/thefuck/archive/master.zip

@liuwankang
Copy link

man ! thank you

@carafelix
Copy link

carafelix commented Dec 30, 2024

To fully support python 3.12 its also needed to merge something like: #1487

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment