diff options
| author | shadchin <[email protected]> | 2022-02-10 16:44:39 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:39 +0300 |
| commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
| tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Lib/weakref.py | |
| parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/weakref.py')
| -rw-r--r-- | contrib/tools/python3/src/Lib/weakref.py | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/contrib/tools/python3/src/Lib/weakref.py b/contrib/tools/python3/src/Lib/weakref.py index 9ebb0a184f2..994ea8aa37d 100644 --- a/contrib/tools/python3/src/Lib/weakref.py +++ b/contrib/tools/python3/src/Lib/weakref.py @@ -2,7 +2,7 @@ This module is an implementation of PEP 205: -https://www.python.org/dev/peps/pep-0205/ +https://www.python.org/dev/peps/pep-0205/ """ # Naming convention: Variables named "wr" are weak reference objects; @@ -33,9 +33,9 @@ __all__ = ["ref", "proxy", "getweakrefcount", "getweakrefs", "WeakSet", "WeakMethod", "finalize"] -_collections_abc.Set.register(WeakSet) -_collections_abc.MutableSet.register(WeakSet) - +_collections_abc.Set.register(WeakSet) +_collections_abc.MutableSet.register(WeakSet) + class WeakMethod(ref): """ A custom `weakref.ref` subclass which simulates a weak reference to @@ -78,14 +78,14 @@ class WeakMethod(ref): if not self._alive or not other._alive: return self is other return ref.__eq__(self, other) and self._func_ref == other._func_ref - return NotImplemented + return NotImplemented def __ne__(self, other): if isinstance(other, WeakMethod): if not self._alive or not other._alive: return self is not other return ref.__ne__(self, other) or self._func_ref != other._func_ref - return NotImplemented + return NotImplemented __hash__ = ref.__hash__ @@ -102,7 +102,7 @@ class WeakValueDictionary(_collections_abc.MutableMapping): # objects are unwrapped on the way out, and we always wrap on the # way in). - def __init__(self, other=(), /, **kw): + def __init__(self, other=(), /, **kw): def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref): self = selfref() if self is not None: @@ -111,25 +111,25 @@ class WeakValueDictionary(_collections_abc.MutableMapping): else: # Atomic removal is necessary since this function # can be called asynchronously by the GC - _atomic_removal(self.data, wr.key) + _atomic_removal(self.data, wr.key) self._remove = remove # A list of keys to be removed self._pending_removals = [] self._iterating = set() - self.data = {} - self.update(other, **kw) + self.data = {} + self.update(other, **kw) - def _commit_removals(self, _atomic_removal=_remove_dead_weakref): - pop = self._pending_removals.pop + def _commit_removals(self, _atomic_removal=_remove_dead_weakref): + pop = self._pending_removals.pop d = self.data # We shouldn't encounter any KeyError, because this method should # always be called *before* mutating the dict. - while True: - try: - key = pop() - except IndexError: - return - _atomic_removal(d, key) + while True: + try: + key = pop() + except IndexError: + return + _atomic_removal(d, key) def __getitem__(self, key): if self._pending_removals: @@ -287,17 +287,17 @@ class WeakValueDictionary(_collections_abc.MutableMapping): else: return o - def update(self, other=None, /, **kwargs): + def update(self, other=None, /, **kwargs): if self._pending_removals: self._commit_removals() d = self.data - if other is not None: - if not hasattr(other, "items"): - other = dict(other) - for key, o in other.items(): + if other is not None: + if not hasattr(other, "items"): + other = dict(other) + for key, o in other.items(): d[key] = KeyedRef(o, self._remove, key) - for key, o in kwargs.items(): - d[key] = KeyedRef(o, self._remove, key) + for key, o in kwargs.items(): + d[key] = KeyedRef(o, self._remove, key) def valuerefs(self): """Return a list of weak references to the values. @@ -313,26 +313,26 @@ class WeakValueDictionary(_collections_abc.MutableMapping): self._commit_removals() return list(self.data.values()) - def __ior__(self, other): - self.update(other) - return self + def __ior__(self, other): + self.update(other) + return self + + def __or__(self, other): + if isinstance(other, _collections_abc.Mapping): + c = self.copy() + c.update(other) + return c + return NotImplemented + + def __ror__(self, other): + if isinstance(other, _collections_abc.Mapping): + c = self.__class__() + c.update(other) + c.update(self) + return c + return NotImplemented + - def __or__(self, other): - if isinstance(other, _collections_abc.Mapping): - c = self.copy() - c.update(other) - return c - return NotImplemented - - def __ror__(self, other): - if isinstance(other, _collections_abc.Mapping): - c = self.__class__() - c.update(other) - c.update(self) - return c - return NotImplemented - - class KeyedRef(ref): """Specialized reference that includes a key corresponding to the value. @@ -373,10 +373,10 @@ class WeakKeyDictionary(_collections_abc.MutableMapping): if self._iterating: self._pending_removals.append(k) else: - try: - del self.data[k] - except KeyError: - pass + try: + del self.data[k] + except KeyError: + pass self._remove = remove # A list of dead weakrefs (keys to be removed) self._pending_removals = [] @@ -390,16 +390,16 @@ class WeakKeyDictionary(_collections_abc.MutableMapping): # because a dead weakref never compares equal to a live weakref, # even if they happened to refer to equal objects. # However, it means keys may already have been removed. - pop = self._pending_removals.pop + pop = self._pending_removals.pop d = self.data - while True: + while True: + try: + key = pop() + except IndexError: + return + try: - key = pop() - except IndexError: - return - - try: - del d[key] + del d[key] except KeyError: pass @@ -508,7 +508,7 @@ class WeakKeyDictionary(_collections_abc.MutableMapping): def setdefault(self, key, default=None): return self.data.setdefault(ref(key, self._remove),default) - def update(self, dict=None, /, **kwargs): + def update(self, dict=None, /, **kwargs): d = self.data if dict is not None: if not hasattr(dict, "items"): @@ -518,26 +518,26 @@ class WeakKeyDictionary(_collections_abc.MutableMapping): if len(kwargs): self.update(kwargs) - def __ior__(self, other): - self.update(other) - return self + def __ior__(self, other): + self.update(other) + return self + + def __or__(self, other): + if isinstance(other, _collections_abc.Mapping): + c = self.copy() + c.update(other) + return c + return NotImplemented + + def __ror__(self, other): + if isinstance(other, _collections_abc.Mapping): + c = self.__class__() + c.update(other) + c.update(self) + return c + return NotImplemented + - def __or__(self, other): - if isinstance(other, _collections_abc.Mapping): - c = self.copy() - c.update(other) - return c - return NotImplemented - - def __ror__(self, other): - if isinstance(other, _collections_abc.Mapping): - c = self.__class__() - c.update(other) - c.update(self) - return c - return NotImplemented - - class finalize: """Class for finalization of weakrefable objects @@ -566,7 +566,7 @@ class finalize: class _Info: __slots__ = ("weakref", "func", "args", "kwargs", "atexit", "index") - def __init__(self, obj, func, /, *args, **kwargs): + def __init__(self, obj, func, /, *args, **kwargs): if not self._registered_with_atexit: # We may register the exit function more than once because # of a thread race, but that is harmless |
