Allow serializing integer valued enums in JSON config dicts

This commit is contained in:
Kovid Goyal 2022-01-25 19:39:50 +05:30
parent 9a0ee46c80
commit cb975976c1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -56,6 +56,9 @@ def to_json(obj):
if hasattr(obj, 'toBase64'): # QByteArray if hasattr(obj, 'toBase64'): # QByteArray
return {'__class__': 'bytearray', return {'__class__': 'bytearray',
'__value__': bytes(obj.toBase64()).decode('ascii')} '__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') raise TypeError(repr(obj) + ' is not JSON serializable')