Skip to content

Commit

Permalink
Merge pull request #289 from simplejson/fix_is_namedtuple_dict_fu
Browse files Browse the repository at this point in the history
v3.17.5
  • Loading branch information
etrepum committed Aug 24, 2021
2 parents 8dce5b0 + 39a269f commit 316b399
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# The short X.Y version.
version = '3.17'
# The full version, including alpha/beta/rc tags.
release = '3.17.4'
release = '3.17.5'

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
DistutilsPlatformError

IS_PYPY = hasattr(sys, 'pypy_translation_info')
VERSION = '3.17.4'
VERSION = '3.17.5'
DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"

with open('README.rst', 'r') as f:
Expand Down
2 changes: 1 addition & 1 deletion simplejson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"""
from __future__ import absolute_import
__version__ = '3.17.4'
__version__ = '3.17.5'
__all__ = [
'dump', 'dumps', 'load', 'loads',
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
Expand Down
16 changes: 12 additions & 4 deletions simplejson/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ def _iterencode_list(lst, _current_indent_level):
else:
_asdict = _namedtuple_as_object and getattr(value, '_asdict', None)
if _asdict and callable(_asdict):
chunks = _iterencode_dict(_asdict(),
dct = _asdict()
if not isinstance(dct, dict):
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
chunks = _iterencode_dict(dct,
_current_indent_level)
elif _tuple_as_array and isinstance(value, tuple):
chunks = _iterencode_list(value, _current_indent_level)
Expand Down Expand Up @@ -641,7 +644,10 @@ def _iterencode_dict(dct, _current_indent_level):
else:
_asdict = _namedtuple_as_object and getattr(value, '_asdict', None)
if _asdict and callable(_asdict):
chunks = _iterencode_dict(_asdict(),
dct = _asdict()
if not isinstance(dct, dict):
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
chunks = _iterencode_dict(dct,
_current_indent_level)
elif _tuple_as_array and isinstance(value, tuple):
chunks = _iterencode_list(value, _current_indent_level)
Expand Down Expand Up @@ -686,8 +692,10 @@ def _iterencode(o, _current_indent_level):
else:
_asdict = _namedtuple_as_object and getattr(o, '_asdict', None)
if _asdict and callable(_asdict):
for chunk in _iterencode_dict(_asdict(),
_current_indent_level):
dct = _asdict()
if not isinstance(dct, dict):
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
for chunk in _iterencode_dict(dct, _current_indent_level):
yield chunk
elif (_tuple_as_array and isinstance(o, tuple)):
for chunk in _iterencode_list(o, _current_indent_level):
Expand Down

0 comments on commit 316b399

Please sign in to comment.