Author: Armin Rigo <[email protected]>
Branch:
Changeset: r97137:44c2b8930353
Date: 2019-08-10 01:16 +0200
http://bitbucket.org/pypy/pypy/changeset/44c2b8930353/
Log: json: bug-to-bug compatibility in a corner case
diff --git a/extra_tests/test_json.py b/extra_tests/test_json.py
--- a/extra_tests/test_json.py
+++ b/extra_tests/test_json.py
@@ -50,3 +50,8 @@
== '{"3": 4, "5": 6}'
assert json.dumps({Ellipsis: 42, 3: 4, 5: 6}, skipkeys=True) \
== '{"3": 4, "5": 6}'
+
+def test_boolean_as_dict_key():
+ # it's this way in CPython 2.x. In 3.x it was fixed
+ assert json.dumps({True: 5}) == '{"True": 5}' # != '{"true": 5}'
+ assert json.dumps({False: 5}) == '{"False": 5}'
diff --git a/lib-python/2.7/json/encoder.py b/lib-python/2.7/json/encoder.py
--- a/lib-python/2.7/json/encoder.py
+++ b/lib-python/2.7/json/encoder.py
@@ -301,9 +301,9 @@
elif isinstance(key, float):
key = self.__floatstr(key)
elif key is True:
- key = 'true'
+ key = 'True' # XXX != 'true', bug-to-bug compatibility
elif key is False:
- key = 'false'
+ key = 'False' # XXX != 'false', bug-to-bug compatibility
elif key is None:
key = 'null'
elif isinstance(key, (int, long)):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit