I don't plan to write about every package I port, but there were some
lessons learned from zope.tal that I thought I should mention.

- Running 2to3 on your sources is a good way to identify places that
  need changing, but you'll have to revert most of the actual changes to
  keep it compatible with Python 2.

  I recently learned about a tool called python-modernize[1] that is
  basically 2to3 except it rewrites into a common Python 2 & 3 subset.
  I haven't checked it out yet, but it sounds promising

    [1] http://pypi.python.org/pypi/modernize

- StringIO: while Python-3-style io.StringIO() and io.BytesIO() classes
  exist in Python 2.6+, you can't easily use either them as a
  replacement for StringIO.StringIO or cStringIO.StringIO.  Why?
  Because people tend to mix native (ASCII-only) string literals with
  Unicode objects, and that's a no-no in Python 3 land.

  I didn't like the idea of importing unicode_literals from the
  __future__, or of dropping u'' prefixes everywhere.  Partially because
  I'm not sure that would be enough -- str objects might make it all the
  way though the public API of zope.tal and suddenly code that used to
  work on Python 2 just fine would now explode.  So I went with a
  conditional import -- from cStringIO import StringIO on Python 2 and
  from io import StringIO on Python 3.

- tox/detox make it very easy to add just one more supported Python
  version -- edit tox.ini, run detox, fix tests.  This works with PyPy
  too, not just Python 3.x!

Marius Gedminas
http://pov.lt/ -- Zope 3/BlueBream consulting and development

Attachment: signature.asc
Description: Digital signature

Zope-Dev maillist  -  Zope-Dev@zope.org
**  No cross posts or HTML encoding!  **
(Related lists -
 https://mail.zope.org/mailman/listinfo/zope )

Reply via email to