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 ca4b56a1fc
commit cfe4673240
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -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')