Skip to content
Snippets Groups Projects
Commit 0b6135b3 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

JSONEncoder will behave correctly on weird classes (no __slots and no __dict__)

parent 418e6328
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* added safe_listdir * added safe_listdir
* fixed a bug occurring in Python 3.10 with whereis * 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 * 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 Build system
============ ============
......
__version__ = '2.25.0a3' __version__ = '2.25.0a4'
...@@ -46,13 +46,13 @@ class JSONEncoder(json.JSONEncoder): ...@@ -46,13 +46,13 @@ class JSONEncoder(json.JSONEncoder):
try: try:
for k, v in o.__dict__.items(): for k, v in o.__dict__.items():
dct[k] = self.default(v) dct[k] = self.default(v)
v = dct
except AttributeError: # o has no attribute '__dict__', try with slots except AttributeError: # o has no attribute '__dict__', try with slots
try: try:
for slot in o.__slots__: for slot in o.__slots__:
dct[slot] = self.default(getattr(o, slot)) dct[slot] = self.default(getattr(o, slot))
except AttributeError: # it doesn't have __slots__ either? except AttributeError: # it doesn't have __slots__ either?
v = '<an instance of %s>' % (o.__class__.__name__,) v = '<an instance of %s>' % (o.__class__.__name__,)
v = dct
return v return v
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment