[Imported from Trac: page Python3, version 40]
parent
136ea76380
commit
68387e63ce
12
Python3.md
12
Python3.md
|
@ -153,3 +153,15 @@ Options:
|
|||
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.
|
||||
|
||||
## 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>).
|
Loading…
Reference in a new issue