Skip to content

Commit 7edfb51

Browse files
committed
WIP on sequence methods.
1 parent 6c3d0d9 commit 7edfb51

File tree

1 file changed

+69
-4
lines changed

1 file changed

+69
-4
lines changed

doc/sphinx/source/new_types.rst

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,32 @@ This can be tested thus, in ``tests/unit/test_c_object.py``:
394394
assert err.value.args[0] == "'cObject.ObjectWithAttributes' object has no attribute 'some_attr'"
395395
396396
397+
.. _PySequence_Check(): https://docs.python.org/3/c-api/sequence.html#c.PySequence_Check
398+
.. _PySequence_GetItem(): https://docs.python.org/3/c-api/sequence.html#c.PySequence_GetItem
399+
.. _PySequence_SetItem(): https://docs.python.org/3/c-api/sequence.html#c.PySequence_SetItem
400+
.. _PySequence_Contains(): https://docs.python.org/3/c-api/sequence.html#c.PySequence_Contains
401+
.. _PySequence_Concat(): https://docs.python.org/3/c-api/sequence.html#c.PySequence_Concat
402+
.. _PySequence_InPlaceConcat(): https://docs.python.org/3/c-api/sequence.html#c.PySequence_InPlaceConcat
403+
.. _PySequence_Repeat(): https://docs.python.org/3/c-api/sequence.html#c.PySequence_Repeat
404+
.. _PySequence_InPlaceRepeat(): https://docs.python.org/3/c-api/sequence.html#c.PySequence_InPlaceRepeat
405+
406+
.. _PyObject_SetItem(): https://docs.python.org/3/c-api/object.html#c.PyObject_SetItem
407+
.. _PyObject_DelItem(): https://docs.python.org/3/c-api/object.html#c.PyObject_DelItem
408+
397409
.. _sq_length: https://docs.python.org/3/c-api/typeobj.html#c.PySequenceMethods.sq_length
410+
.. _sq_concat: https://docs.python.org/3/c-api/typeobj.html#c.PySequenceMethods.sq_concat
411+
.. _sq_repeat: https://docs.python.org/3/c-api/typeobj.html#c.PySequenceMethods.sq_repeat
412+
.. _sq_item: https://docs.python.org/3/c-api/typeobj.html#c.PySequenceMethods.sq_item
413+
.. _sq_ass_item: https://docs.python.org/3/c-api/typeobj.html#c.PySequenceMethods.sq_ass_item
414+
.. _sq_ass_contains: https://docs.python.org/3/c-api/typeobj.html#c.PySequenceMethods.sq_ass_contains
415+
.. _sq_inplace_concat: https://docs.python.org/3/c-api/typeobj.html#c.PySequenceMethods.sq_inplace_concat
416+
.. _sq_inplace_repeat: https://docs.python.org/3/c-api/typeobj.html#c.PySequenceMethods.sq_inplace_repeat
417+
398418
.. _lenfunc: https://docs.python.org/3/c-api/typeobj.html#c.lenfunc
419+
.. _binaryfunc: https://docs.python.org/3/c-api/typeobj.html#c.binaryfunc
420+
.. _ssizeargfunc: https://docs.python.org/3/c-api/typeobj.html#c.ssizeargfunc
421+
.. _ssizeobjargproc: https://docs.python.org/3/c-api/typeobj.html#c.ssizeobjargproc
422+
.. _objobjproc: https://docs.python.org/3/c-api/typeobj.html#c.objobjproc
399423

400424
---------------
401425
Sequence Types
@@ -409,18 +433,59 @@ Sequence Types
409433

410434

411435
.. list-table:: Sequence Methods
412-
:widths: 20 70 10
436+
:widths: 30 25 50 70
413437
:header-rows: 1
414438

415439
* - Member
416440
- Function Type
417-
- Function Signatures
441+
- Function Signature
418442
- Description
419443
* - `sq_length`_
420444
- `lenfunc`_
421-
- ``typedef Py_ssize_t (*lenfunc)(PyObject*)``
445+
- ``Py_ssize_t (*lenfunc)(PyObject*)``
422446
- Returns the length of the sequence.
423-
447+
* - `sq_concat`_
448+
- `binaryfunc`_
449+
- ``PyObject *(*binaryfunc)(PyObject*, PyObject*)``
450+
- Takes two sequences and returns a new third one with the first and second concatenated.
451+
* - `sq_repeat`_
452+
- `ssizeargfunc`_
453+
- ``PyObject *(*ssizeargfunc)(PyObject*, Py_ssize_t)``
454+
- Returns a new sequence with the old one repeated n times.
455+
* - `sq_item`_
456+
- `ssizeargfunc`_
457+
- ``PyObject *(*ssizeargfunc)(PyObject*, Py_ssize_t)``
458+
- Returns a *new* reference to the n'th item in the sequence.
459+
Negative indexes are handled appropriately.
460+
Used by `PySequence_GetItem()`_.
461+
This is a fairly crucial implementation for a sequence as `PySequence_Check()`_ detects this to decide if the
462+
object is a sequence.
463+
* - `sq_ass_item`_
464+
- `ssizeobjargproc`_
465+
- ``int (*ssizeobjargproc)(PyObject*, Py_ssize_t, PyObject*)``
466+
- Sets the the n'th item in the sequence.
467+
If the value is NULL the item is deleted and the sequence concatenated (thus called by `PyObject_DelItem()`_).
468+
Negative indexes are handled appropriately.
469+
Used by `PyObject_SetItem()`_.
470+
* - `sq_ass_contains`_
471+
- `objobjproc`_
472+
- ``int (*objobjproc)(PyObject*, PyObject*)``
473+
- Returns non-zero if the sequence contains the given object.
474+
Used by `PySequence_Contains()`_.
475+
This slot may be left to NULL, in this case PySequence_Contains() simply traverses the sequence until it finds a match.
476+
* - `sq_inplace_concat`_
477+
- `binaryfunc`_
478+
- ``PyObject *(*binaryfunc)(PyObject*, PyObject*)``
479+
- Provides in-place concatenation, for example ``+=``.
480+
If this slot is ``NULL`` then `PySequence_Concat()`_ will be used returning a new object.
481+
* - `sq_inplace_repeat`_
482+
- `ssizeargfunc`_
483+
- ``PyObject *(*ssizeargfunc)(PyObject*, Py_ssize_t)``
484+
- Provides in-place concatenation, for example ``+=``.
485+
Returns the existing sequence repeated n times.
486+
If this slot is ``NULL`` then `PySequence_Repeat()`_ will be used returning a new object.
487+
488+
TOOD:
424489

425490
---------------
426491
TODOs:

0 commit comments

Comments
 (0)