A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2003-November/040311.html below:

[Python-Dev] __reversed__ protocol

[Python-Dev] __reversed__ protocolGuido van Rossum guido at python.org
Tue Nov 18 18:06:05 EST 2003
> diff -c -r1.10 enumobject.c
> *** enumobject.c        7 Nov 2003 15:38:08 -0000       1.10
> --- enumobject.c        18 Nov 2003 21:39:51 -0000
> ***************
> *** 174,181 ****
>         if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq))
>                 return NULL;
> 
> !       /* Special case optimization for xrange and lists */
> !       if (PyRange_Check(seq) || PyList_Check(seq))
>                 return PyObject_CallMethod(seq, "__reversed__", NULL);
> 
>         if (!PySequence_Check(seq)) {
> --- 174,181 ----
>         if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq))
>                 return NULL;
> 
> !       if (PyObject_HasAttrString(seq, "__reversed__") &&
> !           PyObject_HasAttrString(seq, "__len__"))
>                 return PyObject_CallMethod(seq, "__reversed__", NULL);
> 
>         if (!PySequence_Check(seq)) {

Note that the two HasAttrString calls can be quite a bit more
expensive than the PyRange_Check and PyList_Check calls...

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4