This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2015-09-18 07:06 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue25160-2to3.patch JelleZijlstra, 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 (15)
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 (JelleZijlstra) * (Python committer) 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 (JelleZijlstra) * (Python committer) 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 Taskaya (BTaskaya) * (Python committer) 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)
msg358127 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-12-09 18:55
> Any reason to keep imp there?

Nope, not anymore.
msg358194 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2019-12-10 14:57
Make sure the standard library doesn't emit those warnings itself.
msg358196 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2019-12-10 15:04
I meant to comment on a different issue, the trigger is stuff like https://bugs.python.org/issue39015 (new deprecationwarnings being generated without cleaning up the standard library first).
msg370778 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-06-05 18:36
imp has been moved to DeprecationWarning and I think its usage in the stdlib has been dealt with at this point.
History
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69347
2020-06-05 18:36:26brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg370778

stage: needs patch -> resolved
2019-12-10 15:04:06lukasz.langasetmessages: + msg358196
2019-12-10 14:57:12lukasz.langasetnosy: + lukasz.langa
messages: + msg358194
2019-12-09 18:55:38brett.cannonsetmessages: + msg358127
2019-12-07 13:31:59BTaskayasetnosy: + BTaskaya
messages: + msg357975
2019-04-07 08:09:12ncoghlansetstatus: closed -> open
resolution: fixed -> (no value)
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:28JelleZijlstrasetmessages: + msg266929
2016-06-02 19:21:08JelleZijlstrasetfiles: + issue25160-2to3.patch
keywords: + patch
2016-06-02 18:59:04JelleZijlstrasetnosy: + JelleZijlstra
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