Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Lib/test/test_json/test_scanstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_bad_escapes(self):

def test_overflow(self):
with self.assertRaises(OverflowError):
self.json.decoder.scanstring(b"xxx", sys.maxsize+1)
self.json.decoder.scanstring("xxx", sys.maxsize+1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was wrongly tested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See:

Python 3.11.6 (v3.11.6:8b6ee5ba3b, Oct  2 2023, 11:18:21) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.decoder.scanstring(b"xxx", 10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: first argument must be a string, not bytes



class TestPyScanstring(TestScanstring, PyTest): pass
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Convert ``_json`` module to use Argument Clinic.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patched by Yoonho Hann.
55 changes: 11 additions & 44 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next

/*[clinic input]
_json.scanstring as py_scanstring
pystr: object
pystr: unicode
end: Py_ssize_t
strict: bool = True
/
Expand All @@ -664,74 +664,41 @@ after the end quote.
static PyObject *
py_scanstring_impl(PyObject *module, PyObject *pystr, Py_ssize_t end,
int strict)
/*[clinic end generated code: output=961740cfae07cdb3 input=9d46d7df7ac749b0]*/
/*[clinic end generated code: output=961740cfae07cdb3 input=cff59e47498f4d8e]*/
{
PyObject *rval;
Py_ssize_t next_end = -1;
if (PyUnicode_Check(pystr)) {
rval = scanstring_unicode(pystr, end, strict, &next_end);
}
else {
PyErr_Format(PyExc_TypeError,
"first argument must be a string, not %.80s",
Py_TYPE(pystr)->tp_name);
return NULL;
}
PyObject *rval = scanstring_unicode(pystr, end, strict, &next_end);
return _build_rval_index_tuple(rval, next_end);
}

/*[clinic input]
_json.encode_basestring_ascii as py_encode_basestring_ascii
pystr: object
pystr: unicode
/

Return an ASCII-only JSON representation of a Python string
[clinic start generated code]*/

static PyObject *
py_encode_basestring_ascii(PyObject *module, PyObject *pystr)
/*[clinic end generated code: output=a8afcd88eba0b572 input=f4085ccd5928ea55]*/
py_encode_basestring_ascii_impl(PyObject *module, PyObject *pystr)
/*[clinic end generated code: output=7b3841287cf211df input=4f3609498aff2de5]*/
{
PyObject *rval;
/* Return an ASCII-only JSON representation of a Python string */
/* METH_O */
if (PyUnicode_Check(pystr)) {
rval = ascii_escape_unicode(pystr);
}
else {
PyErr_Format(PyExc_TypeError,
"first argument must be a string, not %.80s",
Py_TYPE(pystr)->tp_name);
return NULL;
}
return rval;
return ascii_escape_unicode(pystr);
}

/*[clinic input]
_json.encode_basestring as py_encode_basestring
pystr: object
pystr: unicode
/

Return a JSON representation of a Python string
[clinic start generated code]*/

static PyObject *
py_encode_basestring(PyObject *module, PyObject *pystr)
/*[clinic end generated code: output=c87752300776d3b1 input=c3c7ef6e72624f6e]*/
py_encode_basestring_impl(PyObject *module, PyObject *pystr)
/*[clinic end generated code: output=900950f95df3f1c9 input=d42ef714b2c07386]*/
{
PyObject *rval;
/* Return a JSON representation of a Python string */
/* METH_O */
if (PyUnicode_Check(pystr)) {
rval = escape_unicode(pystr);
}
else {
PyErr_Format(PyExc_TypeError,
"first argument must be a string, not %.80s",
Py_TYPE(pystr)->tp_name);
return NULL;
}
return rval;
return escape_unicode(pystr);
}

static void
Expand Down
46 changes: 45 additions & 1 deletion Modules/clinic/_json.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading