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

DeprecationWarning on import imp #190

Closed
peterbe opened this issue Mar 7, 2018 · 7 comments
Closed

DeprecationWarning on import imp #190

peterbe opened this issue Mar 7, 2018 · 7 comments

Comments

@peterbe
Copy link

peterbe commented Mar 7, 2018

/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
@peterbe
Copy link
Author

peterbe commented Mar 7, 2018

@blueyed
Copy link
Contributor

blueyed commented Mar 12, 2018

Thanks for the report.
Please consider providing a PR to fix it, please.

@bittner
Copy link
Member

bittner commented Dec 9, 2018

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. 😒

PR #212 is related to this issue, but it doesn't seem to be a real fix.

@blueyed
Copy link
Contributor

blueyed commented Dec 9, 2018

@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

@bittner
Copy link
Member

bittner commented Dec 9, 2018

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)

@PeterJCLaw
Copy link

Looks like it might be possible to take some inspiration from how importhook works and/or take it as a dependency perhaps.

@gump
Copy link
Contributor

gump commented Sep 27, 2023

This has been resolved in #365

@gump gump closed this as completed Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants