I took some time try to make an old codebase to work with python2/3. Some wat moment from the effort:
1. `StringIO.StringIO` is a PITA. There's no equivalent in Python3 (for a good reason), and you must choose between `io.StringIO` (which only support unicode) and `io.BytesIO` (which only support bytes string). A possible solution is to use `six.StringIO` but it's simply bury the problem. It would be a good idea to think about what string you are dealing with before doing any change around StringIO.
2. The `stat` module contains some helper functions to test st_mode. In Python2, the function will happily accept negative numbers but in Python3 an exception will throw:
$ python2 -c 'import stat; print(stat.S_ISDIR(-1))'
False
$ python3 -c 'import stat; print(stat.S_ISDIR(-1))'
Traceback (most recent call last):
File "", line 1, in
OverflowError: can't convert negative value to unsigned int
3. You can do `def foo(a, (b, c), d)` in Python2:
https://www.python.org/dev/peps/pep-3113/4. You can compare slice with int in Python2:
$ python2 -c 'print(slice(1) > 1)'
True
$ python3 -c 'print(slice(1) > 1)'
Traceback (most recent call last):
File "", line 1, in
TypeError: unorderable types: slice() > int()