django-configurations
django-configurations copied to clipboard
DeprecationWarning on `import imp`
/Users/peterbe/virtualenvs/recipe-server/lib/python3.6/site-packages/configurations/importer.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Thanks for the report. Please consider providing a PR to fix it, please.
Interesting, as of today, there is no such warning anymore:
$ python
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import configurations.importer
>>>
Though, the imp
module is officially deprecated, hence it makes sense to replace the import. Unfortunately, the feature set of importlib
is different from Python 2.7 to Python 3 (no find_module
and load_module
in Python 2), which requires a version check for the import. :unamused:
PR #212 is related to this issue, but it doesn't seem to be a real fix.
@bittner You have to enable the warning.
% python -W error
Python 3.7.1 (default, Oct 22 2018, 10:41:28)
[GCC 8.2.1 20180831] on linux
Type "help", "copyright", "credits" or "license" for more information.
Using histfile /home/user/.python_history (via pythonrc)
>>> import configurations.importer
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "…/Vcs/django-configurations/configurations/importer.py", line 1, in <module>
import imp
File "/usr/lib/python3.7/imp.py", line 33, in <module>
DeprecationWarning, stacklevel=2)
DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
Replacing imp
is fairly tricky. Too much has changed across all Python versions. Also, I'm not totally sure what ConfigurationImporter.find_module and ConfigurationLoader.load_module are doing. Whether it needs to be that complicated.
I found a related issue, though, where it's possible to simplify the current code. (PR #222)
Looks like it might be possible to take some inspiration from how importhook
works and/or take it as a dependency perhaps.
This has been resolved in #365