summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Include/ceval.h1
-rw-r--r--Misc/NEWS2
-rw-r--r--Objects/listobject.c6
-rw-r--r--Python/ceval.c7
-rwxr-xr-xTools/clinic/clinic.py12
5 files changed, 25 insertions, 3 deletions
diff --git a/Include/ceval.h b/Include/ceval.h
index 8760fe5..25976bb 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -223,6 +223,7 @@ PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
#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
diff --git a/Misc/NEWS b/Misc/NEWS
index f317527..8509f52 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -937,6 +937,8 @@ Build
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.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 9c1c9d9..9b42106 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2210,8 +2210,8 @@ PyList_AsTuple(PyObject *v)
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.
@@ -2222,7 +2222,7 @@ Raises ValueError if the value is not present.
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;
diff --git a/Python/ceval.c b/Python/ceval.c
index e682fc1..8ee58f5 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4917,6 +4917,13 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
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"
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 3d51c1d..55faf1e 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -2659,6 +2659,18 @@ class Py_ssize_t_converter(CConverter):
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