From 68387e63ce2156e69ed33543101ecb78d5e968f6 Mon Sep 17 00:00:00 2001 From: itamarst <> Date: Thu, 15 Oct 2020 13:49:16 +0000 Subject: [PATCH] [Imported from Trac: page Python3, version 40] --- Python3.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Python3.md b/Python3.md index a9cace1..e6b54c2 100644 --- a/Python3.md +++ b/Python3.md @@ -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. 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. \ No newline at end of file +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 (). \ No newline at end of file