Skip to content

Commit ed93ca1

Browse files
committed
gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns
1 parent cb07bd2 commit ed93ca1

16 files changed

+526
-206
lines changed

Doc/library/dis.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,25 @@ iterations of the loop.
17371737
.. versionadded:: 3.13
17381738

17391739

1740+
.. opcode:: MATCH_CLASS_ISINSTANCE
1741+
1742+
Read match subject ``Stack[-2]`` and the type object ``Stack[-1]`` from stack.
1743+
Pop ``Stack[-1]`` and push ``True`` or ``False`` for the result of :func:`isinstance`.
1744+
1745+
.. versionadded:: 3.15
1746+
1747+
1748+
.. opcode:: MATCH_CLASS_GET_OPT_ATTR (namei)
1749+
1750+
Replaces ``STACK[-1]`` with ``getattr(STACK[-1], co_names[namei])`` and get
1751+
optional attribute from match subject ``STACK[-2]``.
1752+
1753+
Pop ``Stack[-1]``. If attribute is found, push it and ``True`` onto the stack.
1754+
Otherwise push ``None`` and ``False``.
1755+
1756+
.. versionadded:: 3.15
1757+
1758+
17401759
.. opcode:: MATCH_CLASS (count)
17411760

17421761
``STACK[-1]`` is a tuple of keyword attribute names, ``STACK[-2]`` is the class

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ Known values:
286286
Python 3.15a1 3653 (Fix handling of opcodes that may leave operands on the stack when optimizing LOAD_FAST)
287287
Python 3.15a1 3654 (Fix missing exception handlers in logical expression)
288288
Python 3.15a1 3655 (Fix miscompilation of some module-level annotations)
289+
Python 3.15a1 3656 (Add MATCH_CLASS_ISINSTANCE & MATCH_CLASS_GET_OPT_ATTR)
289290
290291
291292
Python 3.16 will start with 3700
@@ -299,7 +300,7 @@ PC/launcher.c must also be updated.
299300
300301
*/
301302

302-
#define PYC_MAGIC_NUMBER 3655
303+
#define PYC_MAGIC_NUMBER 3656
303304
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
304305
(little-endian) and then appending b'\r\n'. */
305306
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/opcode_ids.h

Lines changed: 100 additions & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)