Fix compatibility with Python > 3.10 #1475
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Module Loading for Compatibility with Python 3.10+
Problem
The
thefuck
project currently uses theimp
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:Solution
This PR introduces a solution that maintains backward compatibility by replacing
imp
withimportlib.util
for Python 3.5+ while providing a fallback toimportlib.machinery.SourceFileLoader
for Python 3.3 and 3.4. For even older versions, it keeps the final fallback toimp
, ensuring compatibility across a wide range of Python versions.Changes
imp
module import with the following structure:importlib.util
for Python 3.5+.importlib.machinery.SourceFileLoader
for Python 3.3 and 3.4.imp
module for Python versions below 3.3.Impact
ModuleNotFoundError
.Resolved Issues
This PR closes the following issues:
I'm hoping that's all of them, sorry if I missed any.