Index: Lib/abc.py =================================================================== --- Lib/abc.py (revision 79538) +++ Lib/abc.py (working copy) @@ -3,6 +3,7 @@ """Abstract Base Classes (ABCs) according to PEP 3119.""" +from _weakrefset import WeakSet # Instance of old-style class class _C: pass @@ -93,9 +94,9 @@ abstracts.add(name) cls.__abstractmethods__ = frozenset(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 @@ -126,7 +127,7 @@ """Override for isinstance(instance, cls).""" # Inline the cache checking when it's simple. subclass = getattr(instance, '__class__', None) - if subclass in cls._abc_cache: + if subclass is not None and subclass in cls._abc_cache: return True subtype = type(instance) # Old-style instances @@ -150,7 +151,7 @@ # 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 Index: Modules/Setup.dist =================================================================== --- Modules/Setup.dist (revision 79538) +++ Modules/Setup.dist (working copy) @@ -118,6 +118,7 @@ # if $HOME is not set _sre _sre.c # Fredrik Lundh's new regular expressions _codecs _codecsmodule.c # access to the builtin codecs and codec registry +_weakref _weakref.c # weak references # The zipimport module is always imported at startup. Having it as a # builtin module avoids some bootstrapping problems and reduces overhead.