Skip to content

Commit 9387fac

Browse files
authored
bpo-43977: Document the new pattern matching type flags (GH-25734)
1 parent cbb7b9e commit 9387fac

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Doc/c-api/typeobj.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,50 @@ and :c:type:`PyType_Type` effectively act as defaults.)
12191219
.. versionadded:: 3.10
12201220

12211221

1222+
.. data:: Py_TPFLAGS_MAPPING
1223+
1224+
This bit indicates that instances of the class may match mapping patterns
1225+
when used as the subject of a :keyword:`match` block. It is automatically
1226+
set when registering or subclassing :class:`collections.abc.Mapping`, and
1227+
unset when registering :class:`collections.abc.Sequence`.
1228+
1229+
.. note::
1230+
1231+
:const:`Py_TPFLAGS_MAPPING` and :const:`Py_TPFLAGS_SEQUENCE` are
1232+
mutually exclusive; it is an error enable both flags simultaneously.
1233+
1234+
**Inheritance:**
1235+
1236+
This flag is inherited by types that do not already set
1237+
:const:`Py_TPFLAGS_SEQUENCE`.
1238+
1239+
.. seealso:: :pep:`634` -- Structural Pattern Matching: Specification
1240+
1241+
.. versionadded:: 3.10
1242+
1243+
1244+
.. data:: Py_TPFLAGS_SEQUENCE
1245+
1246+
This bit indicates that instances of the class may match sequence patterns
1247+
when used as the subject of a :keyword:`match` block. It is automatically
1248+
set when registering or subclassing :class:`collections.abc.Sequence`, and
1249+
unset when registering :class:`collections.abc.Mapping`.
1250+
1251+
.. note::
1252+
1253+
:const:`Py_TPFLAGS_MAPPING` and :const:`Py_TPFLAGS_SEQUENCE` are
1254+
mutually exclusive; it is an error enable both flags simultaneously.
1255+
1256+
**Inheritance:**
1257+
1258+
This flag is inherited by types that do not already set
1259+
:const:`Py_TPFLAGS_MAPPING`.
1260+
1261+
.. seealso:: :pep:`634` -- Structural Pattern Matching: Specification
1262+
1263+
.. versionadded:: 3.10
1264+
1265+
12221266
.. c:member:: const char* PyTypeObject.tp_doc
12231267
12241268
An optional pointer to a NUL-terminated C string giving the docstring for this
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Document the new :const:`Py_TPFLAGS_MAPPING` and
2+
:const:`Py_TPFLAGS_SEQUENCE` type flags.

0 commit comments

Comments
 (0)