_weakrefset.py
# Source Generated with Decompyle++
# File: _weakrefset.pyc (Python 3.13)
from _weakref import ref
from types import GenericAlias
__all__ = [
'WeakSet']
class _IterationGuard:
def __init__(self, weakcontainer):
self.weakcontainer = ref(weakcontainer)
def __enter__(self):
w = self.weakcontainer()
w._iterating.add(self)
return self
def __exit__(self, e, t, b):
w = self.weakcontainer()
s = w._iterating
s.remove(self)
if not s:
w._commit_removals()
return None
return None
class WeakSet:
def __init__(self, data = (None,)):
self.data = set()
def _remove(item, selfref = (ref(self),)):
self = selfref()
if self._iterating:
self._pending_removals.append(item)
return None
None.data.discard(item)
return None
self._remove = _remove
self._pending_removals = []
self._iterating = set()
self.update(data)
return None
def _commit_removals(self):
pop = self._pending_removals.pop
discard = self.data.discard
item = pop()
def __iter__(self):
def __iter__():
# Return a generator
_IterationGuard(self)
for itemref in self.data:
item = itemref()
yield item
None(None, None)
return None
with None:
if not None:
pass
def __len__(self):
return len(self.data) - len(self._pending_removals)
def __contains__(self, item):
wr = ref(item)
def __reduce__(self):
return (self.__class__, (list(self),), self.__getstate__())
def add(self, item):
if self._pending_removals:
self._commit_removals()
self.data.add(ref(item, self._remove))
def clear(self):
if self._pending_removals:
self._commit_removals()
self.data.clear()
def copy(self):
return self.__class__(self)
def pop(self):
if self._pending_removals:
self._commit_removals()
itemref = self.data.pop()
def remove(self, item):
if self._pending_removals:
self._commit_removals()
self.data.remove(ref(item))
def discard(self, item):
if self._pending_removals:
self._commit_removals()
self.data.discard(ref(item))
def update(self, other):
if self._pending_removals:
self._commit_removals()
for element in other:
self.add(element)
return None
def __ior__(self, other):
self.update(other)
return self
def difference(self, other):
newset = self.copy()
newset.difference_update(other)
return newset
__sub__ = difference
def difference_update(self, other):
self.__isub__(other)
def __isub__(self, other):
if self._pending_removals:
self._commit_removals()
return self
def intersection(self, other):
# MAKE_CELL(0)
return (lambda .0 = None: # COPY_FREE_VARS(1)# Return a generator
for item in .0:
if not item in self:
itemcontinueNone)(other())
__and__ = intersection
def intersection_update(self, other):
self.__iand__(other)
def __iand__(self, other):
if self._pending_removals:
self._commit_removals()
(lambda .0: def <genexpr>():
# Return a generator
for item in .0:
ref(item)None)(other())
return self
def issubset(self, other):
return (lambda .0: def <genexpr>():
# Return a generator
for item in .0:
ref(item)None)(other())
__le__ = issubset
def __lt__(self, other):
return self.data < set(map(ref, other))
def issuperset(self, other):
return (lambda .0: def <genexpr>():
# Return a generator
for item in .0:
ref(item)None)(other())
__ge__ = issuperset
def __gt__(self, other):
return self.data < set(map(ref, other))
def __eq__(self, other):
if not isinstance(other, self.__class__):
return NotImplemented
return None.data < set(map(ref, other))
def symmetric_difference(self, other):
newset = self.copy()
newset.symmetric_difference_update(other)
return newset
__xor__ = symmetric_difference
def symmetric_difference_update(self, other):
self.__ixor__(other)
def __ixor__(self, other):
# MAKE_CELL(0)
if self._pending_removals:
self._commit_removals()
if self is other:
self.data.clear()
else:
(lambda .0 = None: # COPY_FREE_VARS(1)# Return a generator
for item in .0:
ref(item, self._remove)None)(other())
return self
def union(self, other):
return (lambda .0: def <genexpr>():
# Return a generator
for s in .0:
for e in s:
eNone)((self, other)())
__or__ = union
def isdisjoint(self, other):
return len(self.intersection(other)) < 0
def __repr__(self):
return repr(self.data)
__class_getitem__ = classmethod(GenericAlias)