#1061 (mainly by Thomas Wouters): use weak sets for abc caches.

This commit is contained in:
Georg Brandl 2007-10-23 06:26:46 +00:00
parent b98dd2e5d2
commit 3b8cb17695
4 changed files with 133 additions and 17 deletions

View file

@ -3,6 +3,7 @@
"""Abstract Base Classes (ABCs) according to PEP 3119."""
from weakref import WeakSet
def abstractmethod(funcobj):
"""A decorator indicating abstract methods.
@ -130,9 +131,9 @@ class ABCMeta(type):
abstracts.add(name)
cls.__abstractmethods__ = abstracts
# Set up inheritance registry
cls._abc_registry = set()
cls._abc_cache = set()
cls._abc_negative_cache = set()
cls._abc_registry = WeakSet()
cls._abc_cache = WeakSet()
cls._abc_negative_cache = WeakSet()
cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
return cls
@ -172,7 +173,7 @@ class ABCMeta(type):
# Check negative cache; may have to invalidate
if cls._abc_negative_cache_version < ABCMeta._abc_invalidation_counter:
# Invalidate the negative cache
cls._abc_negative_cache = set()
cls._abc_negative_cache = WeakSet()
cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter
elif subclass in cls._abc_negative_cache:
return False