Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The March To 3

The March To 3

The How's and Why's of porting to Python 3.

daniellindsley

April 08, 2013
Tweet

More Decks by daniellindsley

Other Decks in Technology

Transcript

  1. Who? • Daniel Lindsley • Pythonista since 2003 • Djangonaut

    since 2006 • Author of Tastypie / Haystack / itty / others
  2. Changes from 2 to 3 •Removals • Backticks, classic classes

    • <>, apply, reduce, dict.has_key • Others
  3. Changes from 2 to 3 •Changed • print is now

    print() • next() is now __next__() • Better raise syntax • Metaclasses
  4. Changes from 2 to 3 •Changed (cont.) • Faster Decimal

    implementation • Reorganized & spruced up stdlib • Careful with I/O!
  5. Changes from 2 to 3 •New! • Built-in OrderedDict •

    String formatting • dict / set comprehensions • Generator delegation via yield from
  6. Changes from 2 to 3 •New! (cont.) • Built-in virtualenv

    support! • unittest2 by default! • World domination with importlib
  7. The One-time port • Ensure you have good test coverage

    • Use 2to3 to convert the codebase • Run tests & fix until it passes
  8. The Combined 2 & 3 codebase • First, you need

    a venv: •virtualenv -p python3 env3 •. env3/bin/activate
  9. The Combined 2 & 3 codebase • Ensure you have

    good test coverage • Require six as a dependency • Use six to patch over the differences • Run tests in Py3 & fix until it passes... • ...then run tests in Py2 & fix until it passes!