Changes between Version 2 and Version 3 of PortingNotesFor2To3


Ignore:
Timestamp:
12/10/2011 07:55:53 AM (4 years ago)
Author:
vsajip
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PortingNotesFor2To3

    v2 v3  
    2323
    2424* 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 replace
    26   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`.
    2727
    28 * If you see octal constants (such as {{{0777}}}), replace them with the hex value ({{{0x1ff}}} for the {{{0777}}} case), and if
     28* If you see octal constants (such as `0777`), replace them with the hex value (`0x1ff` for the `0777` case), and if
    2929  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`
    3131  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 that
    34   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.
    3535
    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}}}.
     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`.
    3838
    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}}}.
     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`.
    4141
    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.
     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.
    4545
    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)`.
Back to Top