Clarify description of __match_kind__. Drop claims of improved security (#1822)

This commit is contained in:
Mark Shannon 2021-02-19 17:56:52 +00:00 committed by GitHub
parent 79fdaaad0b
commit 89183f61d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 7 deletions

View File

@ -424,12 +424,12 @@ Non-conforming ``__match_kind__``
'''''''''''''''''''''''''''''''''
All classes should ensure that the the value of ``__match_kind__`` follows the specification.
Therefore, implementations can assume, without checking, that all the following are *false*::
Therefore, implementations can assume, without checking, that all the following are true::
(__match_kind__ & (MATCH_SEQUENCE | MATCH_MAPPING)) == (MATCH_SEQUENCE | MATCH_MAPPING)
(__match_kind__ & (MATCH_SELF | MATCH_CLASS)) == (MATCH_SELF | MATCH_CLASS)
(__match_kind__ & (MATCH_SELF | MATCH_DEFAULT)) == (MATCH_SELF | MATCH_DEFAULT)
(__match_kind__ & (MATCH_DEFAULT | MATCH_CLASS)) == (MATCH_DEFAULT | MATCH_CLASS)
(__match_kind__ & (MATCH_SEQUENCE | MATCH_MAPPING)) != (MATCH_SEQUENCE | MATCH_MAPPING)
(__match_kind__ & (MATCH_SELF | MATCH_CLASS)) != (MATCH_SELF | MATCH_CLASS)
(__match_kind__ & (MATCH_SELF | MATCH_DEFAULT)) != (MATCH_SELF | MATCH_DEFAULT)
(__match_kind__ & (MATCH_DEFAULT | MATCH_CLASS)) != (MATCH_DEFAULT | MATCH_CLASS)
Thus, implementations can assume that ``__match_kind__ & MATCH_SEQUENCE`` implies ``(__match_kind__ & MATCH_MAPPING) == 0``, and vice-versa.
Likewise for ``MATCH_SELF``, ``MATCH_CLASS`` and ``MATCH_DEFAULT``.
@ -482,8 +482,7 @@ Implementations are also allowed to freely replace ``isinstance(obj, cls)`` with
Security Implications
=====================
Preventing the possible registering or unregistering of classes as sequences or a mappings, that PEP 634 allows,
should improve security. However, the advantage is slight and is not a motivation for this PEP.
None.
Implementation
==============