Skip to content

Commit c3090d9

Browse files
Towaijimiss-islington
authored andcommitted
gh-145591: Move slicing note to __getitem__ (GH-145606)
(cherry picked from commit 2114da9) Co-authored-by: Ali Towaiji <145403626+Towaiji@users.noreply.github.com>
1 parent 6d9221c commit c3090d9

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

Doc/reference/datamodel.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,21 +3226,6 @@ through the object's keys; for sequences, it should iterate through the values.
32263226
.. versionadded:: 3.4
32273227

32283228

3229-
.. index:: pair: object; slice
3230-
3231-
.. note::
3232-
3233-
Slicing is done exclusively with the following three methods. A call like ::
3234-
3235-
a[1:2] = b
3236-
3237-
is translated to ::
3238-
3239-
a[slice(1, 2, None)] = b
3240-
3241-
and so forth. Missing slice items are always filled in with ``None``.
3242-
3243-
32443229
.. method:: object.__getitem__(self, subscript)
32453230

32463231
Called to implement *subscription*, that is, ``self[subscript]``.
@@ -3263,6 +3248,22 @@ through the object's keys; for sequences, it should iterate through the values.
32633248
should raise an :exc:`LookupError` or one of its subclasses
32643249
(:exc:`IndexError` for sequences; :exc:`KeyError` for mappings).
32653250

3251+
.. index:: pair: object; slice
3252+
3253+
.. note::
3254+
3255+
Slicing is handled by :meth:`!__getitem__`, :meth:`~object.__setitem__`,
3256+
and :meth:`~object.__delitem__`.
3257+
A call like ::
3258+
3259+
a[1:2] = b
3260+
3261+
is translated to ::
3262+
3263+
a[slice(1, 2, None)] = b
3264+
3265+
and so forth. Missing slice items are always filled in with ``None``.
3266+
32663267
.. note::
32673268

32683269
The sequence iteration protocol (used, for example, in :keyword:`for`

0 commit comments

Comments
 (0)