diff options
author | Guido van Rossum <guido@python.org> | 2006-03-07 18:50:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-03-07 18:50:55 (GMT) |
commit | 38fff8c4e4276e4e57660a78f305e68bfa87874b (patch) | |
tree | 5f79c06159053f9c7113410fc69dccba01e331ab /Modules/operator.c | |
parent | 9d7855076a8e030e30459de685e762f63bdecac6 (diff) | |
download | cpython-38fff8c4e4276e4e57660a78f305e68bfa87874b.zip cpython-38fff8c4e4276e4e57660a78f305e68bfa87874b.tar.gz cpython-38fff8c4e4276e4e57660a78f305e68bfa87874b.tar.bz2 |
Checking in the code for PEP 357.
This was mostly written by Travis Oliphant.
I've inspected it all; Neal Norwitz and MvL have also looked at it
(in an earlier incarnation).
Diffstat (limited to 'Modules/operator.c')
-rw-r--r-- | Modules/operator.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Modules/operator.c b/Modules/operator.c index 1a2ef85..53144f1 100644 --- a/Modules/operator.c +++ b/Modules/operator.c @@ -130,6 +130,20 @@ op_ipow(PyObject *s, PyObject *a) return NULL; } +static PyObject * +op_index(PyObject *s, PyObject *a) +{ + Py_ssize_t i; + PyObject *a1; + if (!PyArg_UnpackTuple(a,"index", 1, 1, &a1)) + return NULL; + i = PyNumber_Index(a1); + if (i == -1 && PyErr_Occurred()) + return NULL; + else + return PyInt_FromSsize_t(i); +} + static PyObject* is_(PyObject *s, PyObject *a) { @@ -229,6 +243,7 @@ spam1o(isMappingType, spam1(is_, "is_(a, b) -- Same as a is b.") spam1(is_not, "is_not(a, b) -- Same as a is not b.") +spam2(index, __index__, "index(a) -- Same as a.__index__()") spam2(add,__add__, "add(a, b) -- Same as a + b.") spam2(sub,__sub__, "sub(a, b) -- Same as a - b.") spam2(mul,__mul__, "mul(a, b) -- Same as a * b.") |