classification
Title: Stop using deprecated imp module; imp should now emit a real DeprecationWarning
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, BTaskaya, Jelle Zijlstra, berker.peksag, brett.cannon, eric.snow, ncoghlan, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2015-09-18 07:06 by vstinner, last changed 2019-12-07 13:31 by BTaskaya.

Files
File name Uploaded Description Edit
issue25160-2to3.patch Jelle Zijlstra, 2016-06-02 19:21 patch for lib2to3 review
Pull Requests
URL Status Linked Edit
PR 11787 merged brandtbucher, 2019-02-08 03:24
PR 11787 merged brandtbucher, 2019-02-08 03:24
Messages (11)
msg250946 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-18 07:06
The imp module is deprecated since Python 3.4. In Python 3.4, imp uses a PendingDeprecationWarning, and Python 3.5... hum, still a PendingDeprecationWarning. It was not supposed to become a real DeprecationWarning?

Anyway, the imp module is still used in some places of the Python stdlib:

Lib/modulefinder.py:14:    import imp
Python/makeopcodetargets.py:9:import imp
Tools/i18n/pygettext.py:159:import imp
Tools/importbench/importbench.py:10:import imp

modulefinder explicitly ignore the warning :-(

with warnings.catch_warnings():
    warnings.simplefilter('ignore', PendingDeprecationWarning)
    import imp
msg250948 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-09-18 07:11
> Python/makeopcodetargets.py:9:import imp

See issue 20021.
msg250949 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-18 07:12
New changeset 03cd8340e0ce by Victor Stinner in branch '3.5':
Issue #25160: Fix import_init() comments and messages
https://hg.python.org/cpython/rev/03cd8340e0ce
msg250950 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-09-18 07:19
> Lib/modulefinder.py:14:    import imp

I forgot to link issue 20020 in my earlier message :)
msg262467 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-03-25 23:36
> Tools/i18n/pygettext.py:159:import imp

I opened the issue #26639 for it.


>> Python/makeopcodetargets.py:9:import imp
> See issue 20021.

I pushed the change f682b620c64d but I forgot about the issue #20021. Let's discuss there about this script.


> Tools/importbench/importbench.py:10:import imp

I think that it's fine to keep imp there.


> Lib/modulefinder.py:14:    import imp

This one requires more work than the other.
msg266914 - (view) Author: Jelle Zijlstra (Jelle Zijlstra) * (Python triager) Date: 2016-06-02 18:59
Current status:

- 2to3 replaces reload() calls with imp.reload
- Lib/modulefinder.py imports imp and uses it 10 or so times, mostly for constants
- Lib/xml/sax/__init__.py uses imp on Jython only
- Python/makeopcodetargets.py falls back to imp if importlib is not available. 
- Tools/importbench/importbench.py uses imp a number of times.

I'll work on replacing some of these.
msg266929 - (view) Author: Jelle Zijlstra (Jelle Zijlstra) * (Python triager) Date: 2016-06-02 19:25
One more:

- lib/pkgutil.py in _import_imp (amusingly) uses importlib with silenced warnings to import imp.
msg266931 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-06-02 19:28
> - 2to3 replaces reload() calls with imp.reload

There is an already open issue for this: Issue 21446.
msg339564 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2019-04-07 08:07
Fixed for Python 3.8 via the patch for #35936.
msg339565 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2019-04-07 08:09
Oops, this covers more than just modulefinder - reopening until the other remaining uses of the imp module have been removed.
msg357975 - (view) Author: Batuhan (BTaskaya) * Date: 2019-12-07 13:31
@vstinner 

> Tools/importbench/importbench.py:10:import imp
> I think that it's fine to keep imp there. 

Any reason to keep imp there? We can just port it to sole importlib (it already uses it in some places)
History
Date User Action Args
2019-12-07 13:31:59BTaskayasetnosy: + BTaskaya
messages: + msg357975
2019-04-07 08:09:12ncoghlansetstatus: closed -> open
resolution: fixed ->
messages: + msg339565

stage: resolved -> needs patch
2019-04-07 08:07:41ncoghlansetstatus: open -> closed

versions: + Python 3.8, - Python 3.6
nosy: + ncoghlan

messages: + msg339564
resolution: fixed
stage: patch review -> resolved
2019-02-08 03:24:25brandtbuchersetstage: needs patch -> patch review
pull_requests: + pull_request11787
2019-02-08 03:24:14brandtbuchersetstage: needs patch -> needs patch
pull_requests: + pull_request11786
2016-06-02 19:28:30berker.peksagsetmessages: + msg266931
2016-06-02 19:25:28Jelle Zijlstrasetmessages: + msg266929
2016-06-02 19:21:08Jelle Zijlstrasetfiles: + issue25160-2to3.patch
keywords: + patch
2016-06-02 18:59:04Jelle Zijlstrasetnosy: + Jelle Zijlstra
messages: + msg266914
2016-03-25 23:36:50vstinnersetnosy: + eric.snow
2016-03-25 23:36:33vstinnersetmessages: + msg262467
2015-10-04 02:13:41Arfreversetnosy: + Arfrever
2015-09-18 07:19:24berker.peksagsetmessages: + msg250950
2015-09-18 07:12:35python-devsetnosy: + python-dev
messages: + msg250949
2015-09-18 07:11:52berker.peksagsettype: enhancement
components: + Library (Lib)
versions: - Python 3.5
nosy: + berker.peksag

messages: + msg250948
stage: needs patch
2015-09-18 07:06:19vstinnercreate