From 0b6135b379da77f2736f8f862e926a62be97307f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Thu, 7 Mar 2024 09:14:17 +0100 Subject: [PATCH] JSONEncoder will behave correctly on weird classes (no __slots and no __dict__) --- CHANGELOG.md | 1 + satella/__init__.py | 2 +- satella/json.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9110c8f..6efb9ace 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * added safe_listdir * fixed a bug occurring in Python 3.10 with whereis * DirectorySource will raise an exception if directory does not exist and on_fail is set to RAISE +* JSONEncoder will behave correctly on weird classes (no __slots and no __dict__) Build system ============ diff --git a/satella/__init__.py b/satella/__init__.py index b8a2e669..2449a86b 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.25.0a3' +__version__ = '2.25.0a4' diff --git a/satella/json.py b/satella/json.py index 9a74d000..1975a4f4 100644 --- a/satella/json.py +++ b/satella/json.py @@ -46,13 +46,13 @@ class JSONEncoder(json.JSONEncoder): try: for k, v in o.__dict__.items(): dct[k] = self.default(v) + v = dct except AttributeError: # o has no attribute '__dict__', try with slots try: for slot in o.__slots__: dct[slot] = self.default(getattr(o, slot)) except AttributeError: # it doesn't have __slots__ either? v = '<an instance of %s>' % (o.__class__.__name__,) - v = dct return v -- GitLab