Changes between Version 5 and Version 6 of PortingNotesFor2To3
- Timestamp:
- Dec 10, 2011, 8:18:14 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PortingNotesFor2To3
v5 v6 3 3 Please 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. 4 4 ---- 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.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 these guidelines should also apply to the work of porting Django apps to work on the same basis. 6 6 7 7 * 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 … … 67 67 You can grep the instances of those calls in the ported Django code to see how it's done. 68 68 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`. 70 70 71 71 * 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, do72 a `__nonzero__` method, add `__bool__ = __nonzero__` in the same way. Where you see `x.next()` used to iterate, do 73 73 `from django.utils.py3 import next` and replace using the pattern `x.next()` -> `next(x)` (where `x` might be an expression 74 74 rather than just a name). 75 75 76 76 * 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.