[New-bugs-announce] [issue38046] JSON sorting type error

guillard report at bugs.python.org
Fri Sep 6 14:56:05 EDT 2019


New submission from guillard <yoann.reservations at gmail.com>:

If the dict included both str and int keys, sorted returns this error :
TypeError: '<' not supported between instances of 'int' and 'str'

It is a little bit problematic when used with default library behavior, as jsonify in Flask.

possible solution :
try:
    items = sorted(dct.items())
except(TypeError):
    items = sorted(dct.items(), key=lambda kv: str(kv[0]))

----------
files: json_bug_exemple.py
messages: 351268
nosy: yoann934
priority: normal
severity: normal
status: open
title: JSON sorting type error
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48596/json_bug_exemple.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38046>
_______________________________________


More information about the New-bugs-announce mailing list