mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-29852: Argument Clinic Py_ssize_t converter now supports None (#716)
if pass `accept={int, NoneType}`.
This commit is contained in:
parent
ea720fe7e9
commit
762bf40438
20 changed files with 98 additions and 200 deletions
|
@ -541,30 +541,6 @@ PyNumber_AsOff_t(PyObject *item, PyObject *err)
|
|||
}
|
||||
|
||||
|
||||
/* Basically the "n" format code with the ability to turn None into -1. */
|
||||
int
|
||||
_PyIO_ConvertSsize_t(PyObject *obj, void *result) {
|
||||
Py_ssize_t limit;
|
||||
if (obj == Py_None) {
|
||||
limit = -1;
|
||||
}
|
||||
else if (PyIndex_Check(obj)) {
|
||||
limit = PyNumber_AsSsize_t(obj, PyExc_OverflowError);
|
||||
if (limit == -1 && PyErr_Occurred()) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"argument should be integer or None, not '%.200s'",
|
||||
Py_TYPE(obj)->tp_name);
|
||||
return 0;
|
||||
}
|
||||
*((Py_ssize_t *)result) = limit;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
_PyIO_State *
|
||||
_PyIO_get_module_state(void)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue