From c8f7f9cd7cc4168ad45e4d0948922f966dc44e4d Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 19 Feb 2021 18:55:47 +0000 Subject: [PATCH] PEP 653: Make it clearer that MATCH_DEFAULT is the default. (#1823) --- pep-0653.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pep-0653.rst b/pep-0653.rst index 56df6992c..af005ca93 100644 --- a/pep-0653.rst +++ b/pep-0653.rst @@ -119,7 +119,8 @@ Additions to the object model ----------------------------- A ``__match_kind__`` attribute will be added to ``object``. -It should be overridden by classes that want to match class, mapping or sequence patterns. +It should be overridden by classes that want to match mapping or sequence patterns, +or want change the default behavior when matching class patterns. It must be an integer and should be exactly one of these:: 0 @@ -138,6 +139,8 @@ bitwise ``or``\ ed with exactly one of these:: Symbolic constants will be provided both for Python and C, and once defined they will never be changed. +Classes inheriting from ``object`` will inherit ``__match_kind__ = MATCH_DEFAULT``. + Classes which define ``__match_kind__ & MATCH_CLASS`` to be non-zero must implement one additional special attribute, and one special method: @@ -612,6 +615,8 @@ The changes to the semantics can be summarized as: * Class matching is via the ``__attributes__`` attribute and ``__deconstruct__`` method, rather than the ``__match_args__`` method, and allows classes more control over how they are deconstructed. +* The default behavior when matching a class pattern with keyword patterns is changed. + Only the instance dictionary is used. This is to avoid unintended capture of bound-methods. There are no changes to syntax.