classification
Title: 2to3 creates code using deprecated imp module
Type: Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Update reload fixer to use importlib instead of imp
View: 21446
Assigned To: Nosy List: benjamin.peterson, hanno, terry.reedy, xtreak
Priority: normal Keywords:

Created on 2018-12-23 12:58 by hanno, last changed 2018-12-29 02:54 by terry.reedy. This issue is now closed.

Messages (3)
msg332390 - (view) Author: Hanno Boeck (hanno) * Date: 2018-12-23 12:58
2to3 (in python 3.6.6) will rewrite the reload function to use the imp module. However according to [1] "Deprecated since version 3.4: The imp package is pending deprecation in favor of importlib."
Also running the code with warnings enabled will show a deprecation warning.

Example, take this minimal script:

#!/usr/bin/python
import sys
reload(sys)

Running to 2to3 ends up with:
#!/usr/bin/python
import sys
import imp
imp.reload(sys)

$ PYTHONWARNINGS=d python3 foo.py
test.py:3: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp


[1] https://docs.python.org/3/library/imp.html
msg332395 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-12-23 20:49
Seems this came up when the original version of fixer was added as noted in https://bugs.python.org/issue11797#msg206884 . Looking further this seems to be similar to https://bugs.python.org/issue21446 where it was fixed in 3.7 and master to use importlib.reload . Since 3.6 is having it's last bug fix release I am not sure of the backport. Adding benjamin.peterson to the issue .
msg332692 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-12-29 02:54
It was decided in #21446 to only backport the change, labelled an enhancement, to 3.7 and it is now too late to challenge that decision as 3.6 only gets security fixes.
History
Date User Action Args
2018-12-29 02:54:45terry.reedysetstatus: open -> closed

superseder: Update reload fixer to use importlib instead of imp

nosy: + terry.reedy
messages: + msg332692
resolution: duplicate
stage: resolved
2018-12-23 20:49:03xtreaksetnosy: + benjamin.peterson, xtreak
messages: + msg332395
2018-12-23 12:58:37hannocreate