bottle
bottle copied to clipboard
Fix deprecation warning for imp module
Rationale
This PR addresses #1029
Changes
- Fix deprecation warning for
imp
module - Updated on the recent
master
branch (1/4/22)
Testing
With
$ python --version
Python 3.6.3
$ pip install bottle==0.12.13
$ python -W default
>>> import bottle
to reproduce warning
/home/user/.virtualenvs/bottle3.6.3/lib/python3.6/site-packages/bottle.py:38: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
Current version doesn't show this warning and tests are passing.
@defnull tests are green, could you please review?
@hartwork ok, will only leave changes related to import warning. imo there is no harm to include style refactor here as well
@hartwork updated.
It's been a while but I think this PR is just fine as it is now. No hurry until python-3.12 (eventual removal of the imp module?) but the warning is annoying.
Can this be merged @hartwork ?
@n1ngu the changes to .gitignore
are still out of place. Other than that, my review here is from three years and I have stopped using bottle a long time ago, so I will unsubscribe from this pull request. Good luck though.
line 2060: self.module = sys.modules.setdefault(name, imp.new_module(name))
imp module deprecated since version 3.4: The imp module is deprecated in favor of importlib.
line 2060 must be replaced with the following two lines:
new line 1: module_spec = importlib.machinery.ModuleSpec(name, None) new line 2: self.module = sys.modules.setdefault(name, importlib.util.module_from_spec(module_spec))
at the very top of the bottle.py file, add the line:: import importlib.util
@n1ngu @hartwork I can update this PR and revert unrelated changes (like .gitignore
updates). Just let me know what still should be done within this PR.
I think @octaprog7 has a better idea on what should be updated regarding the implementation.
Regarding stylistic changes, I agree the .gitignore file should be reverted. The style changes in the import instruction are debatable, because you are already changing that line. Yet, less changes will make your commit easier to review, now and in a long future whenever somebody reviews the file history.
Just my opinion. Now that hartwork quitted we'll need to draw the attention of another maintainer and see if this suffices.
@n1ngu I've update the code and left only relevant changes related to the imp
module
Looks like irrelevant change now, so closing