From 3b8cb17695209c48bfc618ba265d201e81d1603a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 23 Oct 2007 06:26:46 +0000 Subject: #1061 (mainly by Thomas Wouters): use weak sets for abc caches. --- Lib/abc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Lib/abc.py') diff --git a/Lib/abc.py b/Lib/abc.py index f8e02302782..54dc8e2d975 100644 --- a/Lib/abc.py +++ b/Lib/abc.py @@ -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 -- cgit v1.2.3