Skip to content

Commit 0d7be86

Browse files
committed
Rename rules & condense the note on ambiguity
1 parent 692cede commit 0d7be86

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Doc/reference/expressions.rst

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,17 +1143,15 @@ Formal subscription grammar
11431143
.. grammar-snippet::
11441144
:group: python-grammar
11451145

1146-
subscription: `primary` '[' `subscript` ']'
1147-
subscript: `slice` | `tuple_slices`
1148-
tuple_slices: ','.(`slice` | `starred_expression`)+ [',']
1149-
slice: `proper_slice` | `assignment_expression`
1150-
proper_slice: [`expression`] ":" [`expression`] [ ":" [`expression`] ]
1151-
1152-
There is a semantic difference between the alternatives for *subscript*.
1153-
If *subscript* contains only one unstarred *slice* without a trailing comma,
1154-
it will evaluate to the value of that *slice*.
1155-
Otherwise, *subscript* will evaluate to a :class:`tuple` containing
1156-
the items of *tuple_slices*.
1146+
subscription: `primary` '[' `subscript` ']'
1147+
subscript: `single_subscript` | `tuple_subscript`
1148+
single_subscript: `proper_slice` | `assignment_expression`
1149+
proper_slice: [`expression`] ":" [`expression`] [ ":" [`expression`] ]
1150+
tuple_subscript: ','.(`single_subscript` | `starred_expression`)+ [',']
1151+
1152+
Recall that the ``|`` operator :ref:`denotes *ordered choice* <notation>`.
1153+
Specifically, in :token:`!subscript`, if both alternatives of would match, the
1154+
first (:token:`!single_subscript`) has priority.
11571155

11581156
.. index::
11591157
pair: object; callable

0 commit comments

Comments
 (0)