diff options
author | Bob Ippolito <bob@redivi.com> | 2011-11-18 16:54:36 -0800 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2011-11-18 16:54:36 -0800 |
commit | 793232196f4d341863b791e356e7d95504f82d28 (patch) | |
tree | fe9771bd2925610c1dfa58c2121b5a5d20120327 | |
parent | 52d00503192973f36e629c8869652df1b65eb8be (diff) | |
parent | edfa7651617a5f01d3394e3fc8d8e42aa972c3ff (diff) | |
download | simplejson-793232196f4d341863b791e356e7d95504f82d28.tar.gz |
Merge remote-tracking branch 'singingwolfboy/master' into namedtuple_duck-gh22
-rw-r--r-- | simplejson/_speedups.c | 2 | ||||
-rw-r--r-- | simplejson/encoder.py | 11 |
2 files changed, 5 insertions, 8 deletions
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c index f8b0565..5169923 100644 --- a/simplejson/_speedups.c +++ b/simplejson/_speedups.c @@ -169,7 +169,7 @@ _is_namedtuple(PyObject *obj); static int _is_namedtuple(PyObject *obj) { - return PyTuple_Check(obj) && PyObject_HasAttrString(obj, "_asdict"); + return PyObject_HasAttrString(obj, "_asdict"); } static int diff --git a/simplejson/encoder.py b/simplejson/encoder.py index 5ec7440..383d834 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -155,7 +155,7 @@ class JSONEncoder(object): be supported directly by the encoder. For the inverse, decode JSON with ``parse_float=decimal.Decimal``. - If namedtuple_as_object is true (the default), tuple subclasses with + If namedtuple_as_object is true (the default), objects with ``_asdict()`` methods will be encoded as JSON objects. If tuple_as_array is true (the default), tuple (and subclasses) will @@ -387,8 +387,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, yield buf if isinstance(value, list): chunks = _iterencode_list(value, _current_indent_level) - elif (_namedtuple_as_object and isinstance(value, tuple) and - hasattr(value, '_asdict')): + elif (_namedtuple_as_object and hasattr(value, '_asdict')): chunks = _iterencode_dict(value._asdict(), _current_indent_level) elif _tuple_as_array and isinstance(value, tuple): @@ -472,8 +471,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, else: if isinstance(value, list): chunks = _iterencode_list(value, _current_indent_level) - elif (_namedtuple_as_object and isinstance(value, tuple) and - hasattr(value, '_asdict')): + elif (_namedtuple_as_object and hasattr(value, '_asdict')): chunks = _iterencode_dict(value._asdict(), _current_indent_level) elif _tuple_as_array and isinstance(value, tuple): @@ -507,8 +505,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, elif isinstance(o, list): for chunk in _iterencode_list(o, _current_indent_level): yield chunk - elif (_namedtuple_as_object and isinstance(o, tuple) and - hasattr(o, '_asdict')): + elif (_namedtuple_as_object and hasattr(o, '_asdict')): for chunk in _iterencode_dict(o._asdict(), _current_indent_level): yield chunk elif (_tuple_as_array and isinstance(o, tuple)): |