[Python-Dev] Python 2.x and 3.x use survey, 2014 edition

Nick Coghlan ncoghlan at gmail.com
Wed Dec 17 07:52:39 CET 2014


On 17 December 2014 at 10:45, Chris McDonough <chrism at plope.com> wrote:
> On 12/16/2014 03:09 AM, Barry Warsaw wrote:
>>
>> On Dec 16, 2014, at 02:15 PM, Skip Montanaro wrote:
>>
>>> While he doesn't explicitly say so, I got the distinct impression reading
>>> his recent blog post that he supports one source, not forked sources.
>>
>>
>> I've ported a fair bit of code, both pure-Python and C extensions, both
>> libraries and applications.  For successful library ports to Python 3 that
>> need to remain Python 2 compatible, I would almost always recommend a
>> single
>> source, common dialect, no-2to3 approach.  There may be exceptions, but
>> this
>> strategy has proven effective over and over.  I generally find I don't
>> need
>> `six` but it does provide some nice conveniences that can be helpful.
>> With
>> something like tox running your test suite, it doesn't even have to be
>> painful
>> to maintain.
>
>
> I'll agree; with tox and some automated CI system like travis or jenkins or
> whatever, once you've done the port, it's only a minor nuisance to maintain
> a straddled 2/3 codebase.  Programming in only the subset still isn't much
> fun, but maintenance is slightly easier than I expected it to be.  "Drive
> by" contributions become slightly harder to accept because they often break
> 3 compatibility, and contributors are often unable or unwilling to install
> all the required versions that are tested by tox.

It's worth noting that the last problem can potentially be mitigated
to some degree by taking advantage of the new "pylint --py3k" feature
making it easier to check that code is 2/3 source compatible without
needing a local copy of Python 3 to test against, and without needing
to adhere to pylint's other checks.

As far as Marko's suggestion of maintaining two code bases go, that's
what we do for the standard library, and we've *never* advised anyone
else to do the same. Even before experience showed the source
compatible approach was more practical, the original advice to third
party developers was to use 2to3 to automatically derive the Python 3
version from the Python 2 version and address any compatibility issues
by modifying the Python 2 sources.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list