bottle icon indicating copy to clipboard operation
bottle copied to clipboard

Fix deprecation warning for imp module

Open bmwant opened this issue 6 years ago • 9 comments

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.

bmwant avatar Feb 27 '18 15:02 bmwant

@defnull tests are green, could you please review?

bmwant avatar Feb 27 '18 15:02 bmwant

@hartwork ok, will only leave changes related to import warning. imo there is no harm to include style refactor here as well

bmwant avatar Apr 06 '18 19:04 bmwant

@hartwork updated.

bmwant avatar Apr 10 '18 09:04 bmwant

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 avatar Dec 31 '21 12:12 n1ngu

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

hartwork avatar Dec 31 '21 16:12 hartwork

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

octaprog7 avatar Jan 01 '22 14:01 octaprog7

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

bmwant avatar Jan 01 '22 18:01 bmwant

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 avatar Jan 03 '22 11:01 n1ngu

@n1ngu I've update the code and left only relevant changes related to the imp module

bmwant avatar Jan 04 '22 14:01 bmwant

Looks like irrelevant change now, so closing

bmwant avatar Oct 24 '22 09:10 bmwant