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 compatibility with Python > 3.10 #1475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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

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