[openstack-dev] [swift] Plan to port Swift to Python 3
vstinner at redhat.com
Fri Oct 9 11:38:29 UTC 2015
Le 09/10/2015 12:12, vishal yadav a écrit :
> However I was just checking if you considered using 2to3. I can
> understand that translation using this tool might not cover every area
> in the code more specifically custom/3rd party libraries (non-standard
> python libraries) but IMO it can do fixer translations to much extent.
I tried 2to3, modernize and 2to6 tools in the past, but they produce a
single giant patch with unwanted changes. These tools are written to add
compatibility for all Python versions including Python 2.6 and Python
3.0. In OpenStack, we only care of Python 2.7 and 3.4, so the code can
be simpler. For example, we can simply write u"unicode" instead of
I wrote the sixer tool for OpenStack. Basically, it's the same than
2to6, except that:
- sixer respects OpenStack Coding Style on imports: it groups and sorts
imports. It avoids to have to manually fix individual modified import
which takes a lot of time
- sixer can produce a patch for a single pattern. For example, replace
all unicode with six.text_type but nothing else. Since all changes are
reviewed carefully in OpenStack, it's important to produce "reviewable"
See also my blog article which explains the full rationale:
My patch serie of 6 changes to fix most Python 3 issues was almost fully
generated by sixer. Sometimes, I had to manually fix a few lines because
no tool is perfect ;-) The patch serie:
* "py3: Replace unicode with six.text_type"
* "py3: Replace urllib imports with six.moves.urllib"
* "py3: Use six.reraise() to reraise an exception"
* "py3: Replace gen.next() with next(gen)"
* "Replace itertools.ifilter with six.moves.filter"
* "py3: Replace basestring with six.string_types"
Then I will then use sixer on individual files to fix all Python 3 at once.
More information about the OpenStack-dev