Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json exception #347

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions documentation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,21 @@ Contains classes from Python 3's :mod:`py3:urllib.response` and Python 2's:
* :class:`py2:urllib.addinfourl`


JSON JSONDecodeError Exception
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

.. currentmodule:: six

The Python3 *json* module raises the JSONDecodeError exception when it can't
decode the given json input. The Python2 *json* module raises the ValueError
exception under the same circumstances.

.. data:: JSONDecodeError

A JSONDecodeError exception that can be used to catch exceptions raised by
both the Python2 and Python3 *json* modules.


Advanced - Customizing renames
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Expand Down
2 changes: 2 additions & 0 deletions six.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
binary_type = bytes

MAXSIZE = sys.maxsize
from json import JSONDecodeError
else:
string_types = basestring,
integer_types = (int, long)
Expand All @@ -70,6 +71,7 @@ def __len__(self):
# 64-bit
MAXSIZE = int((1 << 63) - 1)
del X
JSONDecodeError = ValueError


def _add_doc(func, doc):
Expand Down
8 changes: 8 additions & 0 deletions test_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,3 +1039,11 @@ def test_ensure_text(self):
assert converted_unicode == self.UNICODE_EMOJI and isinstance(converted_unicode, str)
# PY3: bytes -> str
assert converted_binary == self.UNICODE_EMOJI and isinstance(converted_unicode, str)

def test_JSONDecodeError():
import json
from six import JSONDecodeError
try:
json.loads('')
except JSONDecodeError:
pass