diff options
author | Mark Shannon <mark@hotpy.org> | 2021-04-30 08:50:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-30 08:50:28 (GMT) |
commit | 069e81ab3da46c441335ca762c4333b7bd91861d (patch) | |
tree | 02716907f4513a812cf2c72309cc4e6f133b3ab3 /Lib/_collections_abc.py | |
parent | 2abbd8f2add5e80b86a965625b9a77ae94a101cd (diff) | |
download | cpython-069e81ab3da46c441335ca762c4333b7bd91861d.zip cpython-069e81ab3da46c441335ca762c4333b7bd91861d.tar.gz cpython-069e81ab3da46c441335ca762c4333b7bd91861d.tar.bz2 |
bpo-43977: Use tp_flags for collection matching (GH-25723)
* Add Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING, add to all relevant standard builtin classes.
* Set relevant flags on collections.abc.Sequence and Mapping.
* Use flags in MATCH_SEQUENCE and MATCH_MAPPING opcodes.
* Inherit Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING.
* Add NEWS
* Remove interpreter-state map_abc and seq_abc fields.
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r-- | Lib/_collections_abc.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index dddf8a2..d92b848 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -793,7 +793,6 @@ MutableSet.register(set) ### MAPPINGS ### - class Mapping(Collection): """A Mapping is a generic container for associating key/value pairs. @@ -804,6 +803,9 @@ class Mapping(Collection): __slots__ = () + # Tell ABCMeta.__new__ that this class should have TPFLAGS_MAPPING set. + __abc_tpflags__ = 1 << 6 # Py_TPFLAGS_MAPPING + @abstractmethod def __getitem__(self, key): raise KeyError @@ -842,7 +844,6 @@ class Mapping(Collection): __reversed__ = None - Mapping.register(mappingproxy) @@ -1011,7 +1012,6 @@ MutableMapping.register(dict) ### SEQUENCES ### - class Sequence(Reversible, Collection): """All the operations on a read-only sequence. @@ -1021,6 +1021,9 @@ class Sequence(Reversible, Collection): __slots__ = () + # Tell ABCMeta.__new__ that this class should have TPFLAGS_SEQUENCE set. + __abc_tpflags__ = 1 << 5 # Py_TPFLAGS_SEQUENCE + @abstractmethod def __getitem__(self, index): raise IndexError @@ -1072,7 +1075,6 @@ class Sequence(Reversible, Collection): 'S.count(value) -> integer -- return number of occurrences of value' return sum(1 for v in self if v is value or v == value) - Sequence.register(tuple) Sequence.register(str) Sequence.register(range) |