#ifndef Py_LIMITED_API
PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
+PyAPI_FUNC(int) _PyEval_SliceIndexOrNone(PyObject *, Py_ssize_t *);
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(void);
#endif
Tools/Demos
-----------
+- bpo-29748: Added the slice index converter in Argument Clinic.
+
- bpo-24037: Argument Clinic now uses the converter `bool(accept={int})` rather
than `int` for semantical booleans. This avoids repeating the default
value for Python and C and will help in converting to `bool` in future.
list.index
value: object
- start: object(converter="_PyEval_SliceIndex", type="Py_ssize_t") = 0
- stop: object(converter="_PyEval_SliceIndex", type="Py_ssize_t", c_default="PY_SSIZE_T_MAX") = sys.maxsize
+ start: slice_index(accept={int}) = 0
+ stop: slice_index(accept={int}, c_default="PY_SSIZE_T_MAX") = sys.maxsize
/
Return first index of value.
static PyObject *
list_index_impl(PyListObject *self, PyObject *value, Py_ssize_t start,
Py_ssize_t stop)
-/*[clinic end generated code: output=ec51b88787e4e481 input=70b7247e398a6999]*/
+/*[clinic end generated code: output=ec51b88787e4e481 input=40ec5826303a0eb1]*/
{
Py_ssize_t i;
return 1;
}
+int
+_PyEval_SliceIndexOrNone(PyObject *v, Py_ssize_t *pi)
+{
+ return v == Py_None || _PyEval_SliceIndex(v, pi);
+}
+
+
#define CANNOT_CATCH_MSG "catching classes that do not inherit from "\
"BaseException is not allowed"
c_ignored_default = "0"
+class slice_index_converter(CConverter):
+ type = 'Py_ssize_t'
+
+ def converter_init(self, *, accept={int, NoneType}):
+ if accept == {int}:
+ self.converter = '_PyEval_SliceIndex'
+ elif accept == {int, NoneType}:
+ self.converter = '_PyEval_SliceIndexOrNone'
+ else:
+ fail("slice_index_converter: illegal 'accept' argument " + repr(accept))
+
+
class float_converter(CConverter):
type = 'float'
default_type = float