@@ -822,7 +822,7 @@ and binds no name. Syntax:
822822
823823``_ `` is a :ref: `soft keyword <soft-keywords >` within any pattern,
824824but only within patterns. It is an identifier, as usual, even within
825- ``match `` headers , ``guards `` , and ``case `` blocks.
825+ ``match `` subject expressions , ``guard `` \ s , and ``case `` blocks.
826826
827827In simple terms, ``_ `` will always succeed.
828828
@@ -900,8 +900,8 @@ sequence pattern.
900900The following is the logical flow for matching a sequence pattern against a
901901subject value:
902902
903- #. If the subject value is not an instance of a
904- :class: ` collections.abc.Sequence ` the sequence pattern fails.
903+ #. If the subject value is not a sequence [ # ]_, the sequence pattern
904+ fails.
905905
906906#. If the subject value is an instance of ``str ``, ``bytes `` or ``bytearray ``
907907 the sequence pattern fails.
@@ -943,7 +943,7 @@ subject value:
943943In simple terms ``[P1, P2, P3, `` ... ``, P<N>] `` matches only if all the following
944944happens:
945945
946- * `` isinstance( <subject>, collections.abc.Sequence) ``
946+ * check `` <subject> `` is a sequence
947947* ``len(subject) == <N> ``
948948* ``P1 `` matches ``<subject>[0] `` (note that this match can also bind names)
949949* ``P2 `` matches ``<subject>[1] `` (note that this match can also bind names)
@@ -975,8 +975,7 @@ runtime error and will raise :exc:`ValueError`.)
975975The following is the logical flow for matching a mapping pattern against a
976976subject value:
977977
978- #. If the subject value is not an instance of :class: `collections.abc.Mapping `,
979- the mapping pattern fails.
978+ #. If the subject value is not a mapping [# ]_,the mapping pattern fails.
980979
981980#. If every key given in the mapping pattern is present in the subject mapping,
982981 and the pattern for each key matches the corresponding item of the subject
@@ -993,7 +992,7 @@ subject value:
993992In simple terms ``{KEY1: P1, KEY2: P2, ... } `` matches only if all the following
994993happens:
995994
996- * `` isinstance( <subject>, collections.abc.Mapping) ``
995+ * check `` <subject> `` is a mapping
997996* ``KEY1 in <subject> ``
998997* ``P1 `` matches ``<subject>[KEY1] ``
999998* ... and so on for the corresponding KEY/pattern pair.
@@ -1526,6 +1525,35 @@ body of a coroutine function.
15261525 there is a :keyword: `finally ` clause which happens to raise another
15271526 exception. That new exception causes the old one to be lost.
15281527
1528+ .. [# ] In pattern matching, a sequence is defined as one of the following:
1529+
1530+ * a class that inherits from :class: `collections.abc.Sequence `
1531+ * a Python class that has been registered as :class: `collections.abc.Sequence `
1532+ * a builtin class that has its (CPython) :data: `Py_TPFLAGS_SEQUENCE ` bit set
1533+ * a class that inherits from any of the above
1534+
1535+ The following standard library classes are sequences:
1536+
1537+ * :class: `array.array `
1538+ * :class: `collections.deque `
1539+ * :class: `list `
1540+ * :class: `memoryview `
1541+ * :class: `range `
1542+ * :class: `tuple `
1543+
1544+ .. note :: Subject values of type ``str``, ``bytes``, and ``bytearray``
1545+ do not match sequence patterns.
1546+
1547+ .. [# ] In pattern matching, a mapping is defined as one of the following:
1548+
1549+ * a class that inherits from :class: `collections.abc.Mapping `
1550+ * a Python class that has been registered as :class: `collections.abc.Mapping `
1551+ * a builtin class that has its (CPython) :data: `Py_TPFLAGS_MAPPING ` bit set
1552+ * a class that inherits from any of the above
1553+
1554+ The standard library classes :class: `dict ` and :class: `types.MappingProxyType `
1555+ are mappings.
1556+
15291557 .. [# ] A string literal appearing as the first statement in the function body is
15301558 transformed into the function's ``__doc__ `` attribute and therefore the
15311559 function's :term: `docstring `.
0 commit comments