Code

Changes between Version 3 and Version 4 of PortingNotesFor2To3


Ignore:
Timestamp:
12/10/11 06:07:31 (3 years ago)
Author:
vsajip
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PortingNotesFor2To3

    v3 v4  
    4545 
    4646* 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`. 
     47  where you can omit `BaseClass` if it is `object`. Remove the `__metaclass__ = XXX` statement from the class body (replacing it with 
     48  `pass` if that's all there was in the class body). 
    4849 
    4950* If you need to reraise an exception, do `from django.utils.py3 import reraise` and invoke it using the form 
    5051  `reraise(type, instance, traceback)`. 
     52 
     53* You will see that `2to3` puts `list()` around calls to methods named `keys`, `values` or `items`. This is sometimes but not always 
     54  necessary, so examine each on a case-by-case basis. In particular, if `values` is called on a queryset, you '''don't''' want to 
     55  wrap with `list()`. 
     56 
     57* There are functions `iterkeys`, `itervalues` and `iteritems` defined in `django.utils.py3`. Import them if there is any reference 
     58  to those methods, and replace using the pattern `x.iterkeys()` -> `iterkeys(x)` (where `x` might be an expression rather than just 
     59  a name). 
     60 
     61* Replace `map` calls with the list comprehensions suggested by `2to3`. If you see `map(None, ...)` you will need to import and use 
     62  `izip_longest` from `django.utils.py3`. 
     63 
     64* If you see `xrange` in the source, just do `from django.utils.py3 import xrange`. 
     65 
     66* If you use anything from `urllib`, `urllib2`, `urlparse`, you will need to import them