Changes between Version 5 and Version 6 of PortingNotesFor2To3


Ignore:
Timestamp:
Dec 10, 2011, 8:18:14 AM (13 years ago)
Author:
Vinay Sajip
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PortingNotesFor2To3

    v5 v6  
    33Please Note: This is work in progress, I am working on the draft, and I will remove "I am working on the draft" when I have finished working on the draft.
    44----
    5 When porting Django so that it works from a single codebase in Python 2.x and 3.x, the following is a rough-and-ready guide which I (Vinay Sajip) followed, and should also apply to the work of porting Django apps to work on the same basis.
     5When porting Django so that it works from a single codebase in Python 2.x and 3.x, the following is a rough-and-ready guide which I (Vinay Sajip) followed, and these guidelines should also apply to the work of porting Django apps to work on the same basis.
    66
    77* Do run `2to3` on the codebase, but pipe the output to a file so that you can examine what changes need to be made, But
     
    6767  You can grep the instances of those calls in the ported Django code to see how it's done.
    6868
    69 * If you're using `StringIO` or `BytesIO`, import them from `django.utils.py3`.
     69* If you're using `StringIO`, `BytesIO`, or `pickle`, import them from `django.utils.py3`.
    7070
    7171* If a class has a `next()` method which is used for iteration, add a line `__next__ = next` just after it in the class. If it has
    72   a `__nonzero__` method, add `__bool__ = __nonzero` in the same way. Where you see `x.next()` used to iterate, do
     72  a `__nonzero__` method, add `__bool__ = __nonzero__` in the same way. Where you see `x.next()` used to iterate, do
    7373  `from django.utils.py3 import next` and replace using the pattern `x.next()` -> `next(x)` (where `x` might be an expression
    7474  rather than just a name).
    7575
    7676* If you define rich comparisons, review how they work in 2.x and 3.x and adapt your code accordingly.
     77
     78* If you use `exec` or `execfile`, use the versions `exec_` and `execfile_` from `django.utils.py3`.
     79
     80* Use `django.utils.py3.maxsize` in place of `sys.maxint`.
     81
     82* Take a look at `django.utils.py3` to see what else you might need to change in your code: everything in there is needed somewhere
     83  in the porting process.
Back to Top