diff options
author | Bob Ippolito <bob@redivi.com> | 2021-08-23 21:32:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-23 21:32:46 -0700 |
commit | 316b399ba5ea2720710203942e1514bd0a9f00f3 (patch) | |
tree | 3e3469eedf611456b8c1a4e57ced45a53314a0fa | |
parent | 8dce5b06d3faf9cc439a56dfa3cbdcde2dd8c8ec (diff) | |
parent | 39a269f8ac829a0e8cb7ee5ff3597227e334b4d0 (diff) | |
download | simplejson-316b399ba5ea2720710203942e1514bd0a9f00f3.tar.gz |
Merge pull request #289 from simplejson/fix_is_namedtuple_dict_fu
v3.17.5
-rw-r--r-- | conf.py | 2 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | simplejson/__init__.py | 2 | ||||
-rw-r--r-- | simplejson/encoder.py | 16 |
4 files changed, 15 insertions, 7 deletions
@@ -44,7 +44,7 @@ copyright = '2021, Bob Ippolito' # 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: @@ -12,7 +12,7 @@ from distutils.errors import CCompilerError, DistutilsExecError, \ 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: diff --git a/simplejson/__init__.py b/simplejson/__init__.py index aecbbaa..c41029e 100644 --- a/simplejson/__init__.py +++ b/simplejson/__init__.py @@ -118,7 +118,7 @@ Serializing multiple objects to JSON lines (newline-delimited JSON):: """ from __future__ import absolute_import -__version__ = '3.17.4' +__version__ = '3.17.5' __all__ = [ 'dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONDecodeError', 'JSONEncoder', diff --git a/simplejson/encoder.py b/simplejson/encoder.py index 7ea172e..2f81cab 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -520,7 +520,10 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, 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) @@ -641,7 +644,10 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, 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) @@ -686,8 +692,10 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, 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): |