diff options
author | Bob Ippolito <bob@redivi.com> | 2015-05-22 09:27:19 -0700 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2015-05-22 09:27:19 -0700 |
commit | c2190efda0e6fdd6783a56a6aeab818b072350a1 (patch) | |
tree | f22f43f9f2bf9fe2085a955f2728a146e7618e43 /simplejson/encoder.py | |
parent | 71c3672396b32b62f35c53668182720f8f3d5ecc (diff) | |
download | simplejson-c2190efda0e6fdd6783a56a6aeab818b072350a1.tar.gz |
attempt to work around an issue with reloading the Decimal modulev3.7.2
Diffstat (limited to 'simplejson/encoder.py')
-rw-r--r-- | simplejson/encoder.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/simplejson/encoder.py b/simplejson/encoder.py index 7f0b037..a266333 100644 --- a/simplejson/encoder.py +++ b/simplejson/encoder.py @@ -3,7 +3,8 @@ from __future__ import absolute_import import re from operator import itemgetter -from decimal import Decimal +# Do not import Decimal directly to avoid reload issues +import decimal from .compat import u, unichr, binary_type, string_types, integer_types, PY3 def _import_speedups(): try: @@ -337,7 +338,7 @@ class JSONEncoder(object): self.namedtuple_as_object, self.tuple_as_array, int_as_string_bitcount, self.item_sort_key, self.encoding, self.for_json, - self.ignore_nan, Decimal) + self.ignore_nan, decimal.Decimal) else: _iterencode = _make_iterencode( markers, self.default, _encoder, self.indent, floatstr, @@ -346,7 +347,7 @@ class JSONEncoder(object): self.namedtuple_as_object, self.tuple_as_array, int_as_string_bitcount, self.item_sort_key, self.encoding, self.for_json, - Decimal=Decimal) + Decimal=decimal.Decimal) try: return _iterencode(o, 0) finally: @@ -389,7 +390,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, _PY3=PY3, ValueError=ValueError, string_types=string_types, - Decimal=Decimal, + Decimal=None, dict=dict, float=float, id=id, @@ -399,6 +400,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, str=str, tuple=tuple, ): + if _use_decimal and Decimal is None: + Decimal = decimal.Decimal if _item_sort_key and not callable(_item_sort_key): raise TypeError("item_sort_key must be None or callable") elif _sort_keys and not _item_sort_key: |