[Imported from Trac: page Python3, version 40]

itamarst 2020-10-15 13:49:16 +00:00
parent 136ea76380
commit 68387e63ce

@ -152,4 +152,16 @@ Options:
1. Create new `util_py3.py` module, move just the things you need, have `util.py` import code from there. 1. Create new `util_py3.py` module, move just the things you need, have `util.py` import code from there.
2. Add conditional imports/declarations to `util.py` so it imports on Python 3 and at least some of the code can be made to work. 2. Add conditional imports/declarations to `util.py` so it imports on Python 3 and at least some of the code can be made to work.
Originally we went with first approach, but plausibly second approach is better. Originally we went with first approach, but plausibly second approach is better.
## Serializing bytes with JSON
In Python 2 you can serialize bytes with `json`. In Python 3 you can't. Real Soon Now there will be utility module `allmydata.util.jsonbytes` that allows encoding bytes on Python 3, to minimize changes.
## Dictionaries with bytes/unicode keys
In Python 2 a key can be bytes or unicode, and it will replace the other one. So the key `b"foo"` is the same as `u"foo"` from dict's perspective. In Python 3 they are different keys.
This can lead to bugs when porting, where you end up with two keys instead of one as some strings become Unicode strings.
The interim solution will likely be dicts that enforce key type to be only bytes or only Unicode (<https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3476#ticket>).