You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
2to3 creates code using deprecated imp module #79751
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/pythonimportsysreload(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
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 .
It was decided in bpo-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.
Activity
hannob commentedon Dec 23, 2018
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:
Running to 2to3 ends up with:
#!/usr/bin/python
import sys
import imp
imp.reload(sys)
[1] https://docs.python.org/3/library/imp.html
tirkarthi commentedon Dec 23, 2018
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 .
terryjreedy commentedon Dec 29, 2018
It was decided in bpo-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.