mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-02-14 04:44:05 +01:00
Allow serializing integer valued enums in JSON config dicts
This commit is contained in:
parent
ca4b56a1fc
commit
cfe4673240
1 changed files with 3 additions and 0 deletions
|
|
@ -50,6 +50,9 @@ def to_json(obj):
|
|||
if hasattr(obj, 'toBase64'): # QByteArray
|
||||
return {'__class__': 'bytearray',
|
||||
'__value__': bytes(obj.toBase64()).decode('ascii')}
|
||||
v = getattr(obj, 'value', None)
|
||||
if isinstance(v, int): # Possibly an enum with integer values like all the Qt enums
|
||||
return v
|
||||
raise TypeError(repr(obj) + ' is not JSON serializable')
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue