Small patch by Travis, who write:
1) fixes typo 2) Adds link to name discussion 3) Suggests adding __index__ slot to integer and long built ins. I neglected to do this for the patch, but it could really simplify much code to have it.
This commit is contained in:
parent
94f3b53a67
commit
c2c0269b9f
16
pep-0357.txt
16
pep-0357.txt
|
@ -67,7 +67,7 @@ Specification:
|
|||
|
||||
3) A new C-API function PyNumber_Index will be added with signature
|
||||
|
||||
Py_ssize_t PyNumber_index (PyObject *obj)
|
||||
Py_ssize_t PyNumber_Index (PyObject *obj)
|
||||
|
||||
which will special-case integer and long integer objects but otherwise
|
||||
return obj->ob_type->tp_as_number->nb_index(obj) if it is available.
|
||||
|
@ -92,10 +92,12 @@ Implementation Plan
|
|||
slots for subscript access and use a special-check for integers to
|
||||
check for the slot as well.
|
||||
|
||||
5) Add PyNumber_Index C-API to return an integer from any
|
||||
5) Add the nb_index slot to integers and long_integers.
|
||||
|
||||
6) Add PyNumber_Index C-API to return an integer from any
|
||||
Python Object that has the nb_index slot.
|
||||
|
||||
6) Add the operator.index(x) function.
|
||||
7) Add the operator.index(x) function.
|
||||
|
||||
|
||||
Possible Concerns
|
||||
|
@ -124,7 +126,10 @@ Possible Concerns
|
|||
can be used any time Python requires an integer internally (such
|
||||
as in "mystring" * 3). The name was suggested by Guido because
|
||||
slicing syntax is the biggest reason for having such a slot and
|
||||
in the end no better name emerged.
|
||||
in the end no better name emerged. See the discussion thread:
|
||||
http://mail.python.org/pipermail/python-dev/2006-February/thread.html#60594
|
||||
for examples of names that were suggested such as "__discrete__" and
|
||||
"__ordinal__".
|
||||
|
||||
Why return Py_ssize_t from nb_index?
|
||||
|
||||
|
@ -136,7 +141,8 @@ Possible Concerns
|
|||
|
||||
Reference Implementation
|
||||
|
||||
Submitted as patch 1429591 to SourceForge.
|
||||
Submitted as patch 1429591 to SourceForge. This patch number does
|
||||
not contain implementation 5.
|
||||
|
||||
Copyright
|
||||
|
||||
|
|
Loading…
Reference in New Issue