Don't serialize I/O wrappers

This removes warnings on `config.get`, where the `logging` configuration
key may also contain the current logging stream and we end up with a
JSONDecodeError when trying to serialize it.
This commit is contained in:
Fabio Manganiello 2023-01-25 00:52:37 +01:00
parent ba31dff06a
commit 334ccc35a2
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
import decimal
import datetime
import io
import logging
import inspect
import json
@ -66,6 +67,10 @@ class Message:
if isinstance(obj, JSONAble):
return obj.to_json()
# Don't serialize I/O wrappers/objects
if isinstance(obj, io.IOBase):
return None
try:
return super().default(obj)
except Exception as e: