Lines Matching refs:self
17 def __init__(self, weakcontainer):
19 self.weakcontainer = ref(weakcontainer)
21 def __enter__(self):
22 w = self.weakcontainer()
24 w._iterating.add(self)
25 return self
27 def __exit__(self, e, t, b):
28 w = self.weakcontainer()
31 s.remove(self)
37 def __init__(self, data=None):
38 self.data = set()
39 def _remove(item, selfref=ref(self)):
40 self = selfref()
41 if self is not None:
42 if self._iterating:
43 self._pending_removals.append(item)
45 self.data.discard(item)
46 self._remove = _remove
48 self._pending_removals = []
49 self._iterating = set()
51 self.update(data)
53 def _commit_removals(self):
54 pop = self._pending_removals.pop
55 discard = self.data.discard
63 def __iter__(self):
64 with _IterationGuard(self):
65 for itemref in self.data:
72 def __len__(self):
73 return len(self.data) - len(self._pending_removals)
75 def __contains__(self, item):
80 return wr in self.data
82 def __reduce__(self):
83 return self.__class__, (list(self),), self.__getstate__()
85 def add(self, item):
86 if self._pending_removals:
87 self._commit_removals()
88 self.data.add(ref(item, self._remove))
90 def clear(self):
91 if self._pending_removals:
92 self._commit_removals()
93 self.data.clear()
95 def copy(self):
96 return self.__class__(self)
98 def pop(self):
99 if self._pending_removals:
100 self._commit_removals()
103 itemref = self.data.pop()
110 def remove(self, item):
111 if self._pending_removals:
112 self._commit_removals()
113 self.data.remove(ref(item))
115 def discard(self, item):
116 if self._pending_removals:
117 self._commit_removals()
118 self.data.discard(ref(item))
120 def update(self, other):
121 if self._pending_removals:
122 self._commit_removals()
124 self.add(element)
126 def __ior__(self, other):
127 self.update(other)
128 return self
130 def difference(self, other):
131 newset = self.copy()
136 def difference_update(self, other):
137 self.__isub__(other)
138 def __isub__(self, other):
139 if self._pending_removals:
140 self._commit_removals()
141 if self is other:
142 self.data.clear()
144 self.data.difference_update(ref(item) for item in other)
145 return self
147 def intersection(self, other):
148 return self.__class__(item for item in other if item in self)
151 def intersection_update(self, other):
152 self.__iand__(other)
153 def __iand__(self, other):
154 if self._pending_removals:
155 self._commit_removals()
156 self.data.intersection_update(ref(item) for item in other)
157 return self
159 def issubset(self, other):
160 return self.data.issubset(ref(item) for item in other)
163 def __lt__(self, other):
164 return self.data < set(map(ref, other))
166 def issuperset(self, other):
167 return self.data.issuperset(ref(item) for item in other)
170 def __gt__(self, other):
171 return self.data > set(map(ref, other))
173 def __eq__(self, other):
174 if not isinstance(other, self.__class__):
176 return self.data == set(map(ref, other))
178 def symmetric_difference(self, other):
179 newset = self.copy()
184 def symmetric_difference_update(self, other):
185 self.__ixor__(other)
186 def __ixor__(self, other):
187 if self._pending_removals:
188 self._commit_removals()
189 if self is other:
190 self.data.clear()
192 self.data.symmetric_difference_update(ref(item, self._remove) for item in other)
193 return self
195 def union(self, other):
196 return self.__class__(e for s in (self, other) for e in s)
199 def isdisjoint(self, other):
200 return len(self.intersection(other)) == 0
202 def __repr__(self):
203 return repr(self.data)