fix: "module importlib has no attribute 'machinery'"
This PR
Since the merge of https://github.com/OfflineIMAP/offlineimap3/pull/190, the following errors happens:
ERROR: module 'importlib' has no attribute 'machinery'
ERROR: Exceptions occurred during the run!
ERROR: AttributeError: module 'importlib' has no attribute 'machinery'
This commit should fix this by importing the required package.
- [X] I've read the DCO.
- [X] I've read the Coding Guidelines
- [X] The relevant informations about the changes stands in the commit message, not here in the message of the pull request.
- [X] Code changes follow the style of the files they change.
- [X] Code is tested (tested with my backup scripts).
References
Additional information
I'm no Python expert but it seems that importlib.machinery is only introduced in Python 3.3 so in order to maintain potential compatibility I added the import in the if clause just before it gets used. Let me know if you prefer if to be at the top of the file
Are you using a pre-3.3 version of Python? I'm not getting this error in either the Python 3.10 provided by the distro I use or the Python 3.12 I got through Conda. Maybe it's time to bump the Python requirement (after all, imaplib2 3.6 requires Python 3.6+ and the latest imaplib2 code in their Git repo requires Python 3.10+); I try my best to make sure my contributions will work in older versions of Python, but the code would be so much less messy without having to make concessions for unreasonably old versions.
I have this error with the latest official python Docker images (3.12.5 as of writing) but I also had it with previous versions (I stopped my investigation after a couple of earlier versions, 3.9 IIRC)
Can confirm this error with Python 3.11.9.
I also needed this patch with Python 3.11.11 on guix system. It worked without it when the package was still using 3.10.
Same here with:
$ python --version
Python 3.11.14