Changeset 388 for python/vendor/current/Lib/abc.py
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/abc.py
r2 r388 3 3 4 4 """Abstract Base Classes (ABCs) according to PEP 3119.""" 5 6 import types 7 8 from _weakrefset import WeakSet 9 10 # Instance of old-style class 11 class _C: pass 12 _InstanceType = type(_C()) 5 13 6 14 … … 89 97 cls.__abstractmethods__ = frozenset(abstracts) 90 98 # Set up inheritance registry 91 cls._abc_registry = set()92 cls._abc_cache = set()93 cls._abc_negative_cache = set()99 cls._abc_registry = WeakSet() 100 cls._abc_cache = WeakSet() 101 cls._abc_negative_cache = WeakSet() 94 102 cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter 95 103 return cls … … 97 105 def register(cls, subclass): 98 106 """Register a virtual subclass of an ABC.""" 99 if not isinstance( cls, type):107 if not isinstance(subclass, (type, types.ClassType)): 100 108 raise TypeError("Can only register classes") 101 109 if issubclass(subclass, cls): … … 122 130 # Inline the cache checking when it's simple. 123 131 subclass = getattr(instance, '__class__', None) 124 if subclass i n cls._abc_cache:132 if subclass is not None and subclass in cls._abc_cache: 125 133 return True 126 134 subtype = type(instance) 135 # Old-style instances 136 if subtype is _InstanceType: 137 subtype = subclass 127 138 if subtype is subclass or subclass is None: 128 139 if (cls._abc_negative_cache_version == … … 143 154 if cls._abc_negative_cache_version < ABCMeta._abc_invalidation_counter: 144 155 # Invalidate the negative cache 145 cls._abc_negative_cache = set()156 cls._abc_negative_cache = WeakSet() 146 157 cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter 147 158 elif subclass in cls._abc_negative_cache:
Note:
See TracChangeset
for help on using the changeset viewer.