Skip to content

Commit 9e8aafb

Browse files
committed
Merge subscriptions and slicings in simple_stmts.rst
1 parent 3495d74 commit 9e8aafb

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

Doc/reference/simple_stmts.rst

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ attributes or items of mutable objects:
9191
: | "[" [`target_list`] "]"
9292
: | `attributeref`
9393
: | `subscription`
94-
: | `slicing`
9594
: | "*" `target`
9695

97-
(See section :ref:`primaries` for the syntax definitions for *attributeref*,
98-
*subscription*, and *slicing*.)
96+
(See section :ref:`primaries` for the syntax definitions for *attributeref*
97+
and *subscription*.)
9998

10099
An assignment statement evaluates the expression list (remember that this can be
101100
a single expression or a comma-separated list, the latter yielding a tuple) and
@@ -107,8 +106,8 @@ right.
107106
pair: target; list
108107

109108
Assignment is defined recursively depending on the form of the target (list).
110-
When a target is part of a mutable object (an attribute reference, subscription
111-
or slicing), the mutable object must ultimately perform the assignment and
109+
When a target is part of a mutable object (an attribute reference or
110+
subscription), the mutable object must ultimately perform the assignment and
112111
decide about its validity, and may raise an exception if the assignment is
113112
unacceptable. The rules observed by various types and the exceptions raised are
114113
given with the definition of the object types (see section :ref:`types`).
@@ -189,9 +188,14 @@ Assignment of an object to a single target is recursively defined as follows.
189188
pair: object; mutable
190189

191190
* If the target is a subscription: The primary expression in the reference is
192-
evaluated. It should yield either a mutable sequence object (such as a list)
193-
or a mapping object (such as a dictionary). Next, the subscript expression is
194191
evaluated.
192+
Next, the subscript expression is evaluated.
193+
Then, the primary's :meth:`~object.__setitem__` method is called with
194+
two arguments: the subscript and the assigned object.
195+
196+
Typically, :meth:`~object.__setitem__` is defined on mutable sequence objects
197+
(such as lists) and mapping objects (such as dictionaries), and behaves as
198+
follows.
195199

196200
.. index::
197201
pair: object; sequence
@@ -214,29 +218,21 @@ Assignment of an object to a single target is recursively defined as follows.
214218
object. This can either replace an existing key/value pair with the same key
215219
value, or insert a new key/value pair (if no key with the same value existed).
216220

217-
For user-defined objects, the :meth:`~object.__setitem__` method is called with
218-
appropriate arguments.
219-
220221
.. index:: pair: slicing; assignment
221222

222-
* If the target is a slicing: The primary expression in the reference is
223-
evaluated. It should yield a mutable sequence object (such as a list). The
224-
assigned object should be a sequence object of the same type. Next, the lower
225-
and upper bound expressions are evaluated, insofar they are present; defaults
226-
are zero and the sequence's length. The bounds should evaluate to integers.
223+
If the target is a slicing: The primary expression should evaluate to
224+
a mutable sequence object (such as a list).
225+
The assigned object should be :term:`iterable`.
226+
The slicing's lower and upper bounds should be integers; if they are ``None``
227+
(or not present), the defaults are zero and the sequence's length.
228+
The bounds should evaluate to integers.
227229
If either bound is negative, the sequence's length is added to it. The
228230
resulting bounds are clipped to lie between zero and the sequence's length,
229231
inclusive. Finally, the sequence object is asked to replace the slice with
230232
the items of the assigned sequence. The length of the slice may be different
231233
from the length of the assigned sequence, thus changing the length of the
232234
target sequence, if the target sequence allows it.
233235

234-
.. impl-detail::
235-
236-
In the current implementation, the syntax for targets is taken to be the same
237-
as for expressions, and invalid syntax is rejected during the code generation
238-
phase, causing less detailed error messages.
239-
240236
Although the definition of assignment implies that overlaps between the
241237
left-hand side and the right-hand side are 'simultaneous' (for example ``a, b =
242238
b, a`` swaps two variables), overlaps *within* the collection of assigned-to
@@ -281,7 +277,7 @@ operation and an assignment statement:
281277

282278
.. productionlist:: python-grammar
283279
augmented_assignment_stmt: `augtarget` `augop` (`expression_list` | `yield_expression`)
284-
augtarget: `identifier` | `attributeref` | `subscription` | `slicing`
280+
augtarget: `identifier` | `attributeref` | `subscription`
285281
augop: "+=" | "-=" | "*=" | "@=" | "/=" | "//=" | "%=" | "**="
286282
: | ">>=" | "<<=" | "&=" | "^=" | "|="
287283
@@ -470,7 +466,7 @@ in the same code block. Trying to delete an unbound name raises a
470466

471467
.. index:: pair: attribute; deletion
472468

473-
Deletion of attribute references, subscriptions and slicings is passed to the
469+
Deletion of attribute references and subscriptions is passed to the
474470
primary object involved; deletion of a slicing is in general equivalent to
475471
assignment of an empty slice of the right type (but even this is determined by
476472
the sliced object).

0 commit comments

Comments
 (0)