summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2021-08-23 21:32:46 -0700
committerGitHub <noreply@github.com>2021-08-23 21:32:46 -0700
commit316b399ba5ea2720710203942e1514bd0a9f00f3 (patch)
tree3e3469eedf611456b8c1a4e57ced45a53314a0fa
parent8dce5b06d3faf9cc439a56dfa3cbdcde2dd8c8ec (diff)
parent39a269f8ac829a0e8cb7ee5ff3597227e334b4d0 (diff)
downloadsimplejson-316b399ba5ea2720710203942e1514bd0a9f00f3.tar.gz
Merge pull request #289 from simplejson/fix_is_namedtuple_dict_fu
v3.17.5
-rw-r--r--conf.py2
-rw-r--r--setup.py2
-rw-r--r--simplejson/__init__.py2
-rw-r--r--simplejson/encoder.py16
4 files changed, 15 insertions, 7 deletions
diff --git a/conf.py b/conf.py
index 9809d1a..bc79a42 100644
--- a/conf.py
+++ b/conf.py
@@ -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:
diff --git a/setup.py b/setup.py
index 92a2108..74fc2ce 100644
--- a/setup.py
+++ b/setup.py
@@ -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):