I was looking for this feature, but didn't see it in the documentation so I'm opening a feature request.
I'd love to see a fixer which takes Python 2/3 compatible code and removes the Python 2 support as best as possible.
This would:
__future__
imports (print_function
for example)from future import standard_library
and standard_library.install_aliases()
linesfrom builtins import *
linesfrom future.utils import python_2_unicode_compatible
If such a fixer already exists, I'd love to know about it.
A number of my clients are using future
to upgrade their code to Python 3 and then dropping Python 2 support shortly afterward and such a fixer would be very helpful for them.
If it exists, then it's not documented well. I had to manually remove all that. Use of a fixture that auto-ran maybe with a flag such as -3
to mean only refactor for 3 compliance and ignore python2 compatibility would be great.
I made some transformations myself and bundled them up into a script. It's currently available here: https://github.com/purplediane/drop2
A related tool, with some overlap (namely __future__
imports):
Other notable things:
u
prefix(object)
from class
definitionssuper()
callsmock
importsThat said, I was able to use sed
for standard_library
:
sed -i '' '/.*standard_library.*/d' **/*.py
-from future import standard_library
-standard_library.install_aliases()
import json
import logging
import urllib.parse
I'm planning to do the same for:
.*python_2_unicode_compatible.*
.*implements_iterator.*
from builtins.*
I'm already aware of pyupgrade and have used it. It is very helpful.
pyupgrade
(plus the pre-commit hook) is a great tool for this purpose. Can we close this FR since the alternative is available?
Most helpful comment
I made some transformations myself and bundled them up into a script. It's currently available here: https://github.com/purplediane/drop2