New issue 2191: json.dumps ensure_ascii=False behavior differs from cpython https://bitbucket.org/pypy/pypy/issues/2191/jsondumps-ensure_ascii-false-behavior
Ryan Campbell: I ran into this recently while trying out pypy on our codebase. Basically, `json.dumps` with `ensure_ascii=False` seems to result in a unicode string being returned in python, but not in pypy. This resulted in a `TypeError: unicode argument expected, got 'str'` when trying to write to a file. Python behavior: ``` macbook:~ $ python Python 2.7.10 (default, Jul 13 2015, 12:18:59) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import json >>> json.dumps('a') '"a"' >>> json.dumps('a', ensure_ascii=False) '"a"' >>> json.dumps(u'a') '"a"' >>> json.dumps(u'a', ensure_ascii=False) u'"a"' >>> ``` PyPy behavior: ``` macbook:~ $ pypy Python 2.7.10 (850edf14b2c75573720f59e95767335fb1affe55, Oct 30 2015, 00:18:27) [PyPy 4.0.0 with GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>> import json >>>> json.dumps('a') '"a"' >>>> json.dumps('a', ensure_ascii=False) '"a"' >>>> json.dumps(u'a') '"a"' >>>> json.dumps(u'a', ensure_ascii=False) '"a"' ``` Possibly related to #1627, since it looks quite similar although the behaviors seem to be reversed... _______________________________________________ pypy-issue mailing list pypy-issue@python.org https://mail.python.org/mailman/listinfo/pypy-issue