Changes between Version 2 and Version 3 of PortingNotesFor2To3
- Timestamp:
- Dec 10, 2011, 7:55:53 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PortingNotesFor2To3
v2 v3 23 23 24 24 * If you see `(int, long)` or `(long, int)` in the source, do `from django.utils.py3 import integer_types` and replace the 25 tuple with `integer_types`. If `long` and `int` appear in tuple along with other values, remove them from the tuple and replace26 the tuple with tuple ` +integer_types`.25 tuple with `integer_types`. If `long` and `int` appear in a tuple along with other values, remove them from the tuple and replace 26 the tuple with tuple ` + integer_types`. 27 27 28 * If you see octal constants (such as {{{0777}}}), replace them with the hex value ({{{0x1ff}}} for the {{{0777}}}case), and if28 * If you see octal constants (such as `0777`), replace them with the hex value (`0x1ff` for the `0777` case), and if 29 29 possible, place the octal constant in a comment so anyone can see what it was originally. 30 * If you see code of the type {{{except ExceptionTypeOrTupleOfExceptionTypes, name_to_bind_to:}}}, see if {{{name_to _bind_to}}}30 * If you see code of the type `except ExceptionTypeOrTupleOfExceptionTypes, name_to_bind_to:`, see if `name_to _bind_to` 31 31 is used in the scope (exception handling clause, or later in the same function or method). If not used, just change the 32 {{{except:}}} statement to {{{except ExceptionTypeOrTupleOfExceptionTypes:}}}and you're done. If used, do one more thing:33 put the code {{{name_to_bind_to = sys.exc_info()[1]}}} just before {{{name_to_bind_to}}}is first used, and make sure that34 the {{{sys}}}module is imported.32 `except:` statement to `except ExceptionTypeOrTupleOfExceptionTypes:` and you're done. If used, do one more thing: 33 put the code `name_to_bind_to = sys.exc_info()[1]` just before `name_to_bind_to` is first used, and make sure that 34 the `sys` module is imported. 35 35 36 * If {{{unicode}}} occurs in the source (i.e. not in comments), do {{{from django.utils.py3 import text_type}}}and replace37 {{{unicode}}} with {{{text_type}}}.36 * If `unicode` occurs in the source (i.e. not in comments), do `from django.utils.py3 import text_type` and replace 37 `unicode` with `text_type`. 38 38 39 * If {{{basestring}}} occurs in the source (i.e. not in comments), do {{{from django.utils.py3 import string_types}}}and replace40 {{{basestring}}} with {{{string_types}}}.39 * If `basestring` occurs in the source (i.e. not in comments), do `from django.utils.py3 import string_types` and replace 40 `basestring` with `string_types`. 41 41 42 * If {{{str}}} occurs in the source (i.e. not in comments), you may need to do {{{from django.utils.py3 import binary_type}}}43 and replace {{{str}}} with {{{binary_type}}}. However, don't use this blindly: {{{str()}}}is sometimes used to convert something44 to text for display, and these occurrences of {{{str()}}}shouldn't need changing.42 * If `str` occurs in the source (i.e. not in comments), you may need to do `from django.utils.py3 import binary_type` 43 and replace `str` with `binary_type`. However, don't use this blindly: `str()` is sometimes used to convert something 44 to text for display, and these occurrences of `str()` shouldn't need changing. 45 45 46 * If you have classes with metaclasses, change them to use the form {{{MyClassWithMetaClass(with_metaclass(MetaClass, BaseClass):}}} 47 where you can omit {{{BaseClass}}} if it is {{{object}}}. 46 * If you have classes with metaclasses, change them to use the form `MyClassWithMetaClass(with_metaclass(MetaClass, BaseClass):` 47 where you can omit `BaseClass` if it is `object`. 48 49 * If you need to reraise an exception, do `from django.utils.py3 import reraise` and invoke it using the form 50 `reraise(type, instance, traceback)`.