From cb975976c1771f664adf0b4e7b721161adefb68e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 25 Jan 2022 19:39:50 +0530 Subject: [PATCH] Allow serializing integer valued enums in JSON config dicts --- src/calibre/utils/config_base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/calibre/utils/config_base.py b/src/calibre/utils/config_base.py index 04c4266f07..c89fecbfc6 100644 --- a/src/calibre/utils/config_base.py +++ b/src/calibre/utils/config_base.py @@ -56,6 +56,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')