Lines Matching refs:self

54             # The self-weakref trick is needed to avoid creating a reference
56 self = self_wr()
57 if self._alive:
58 self._alive = False
60 callback(self)
61 self = ref.__new__(cls, obj, _cb)
62 self._func_ref = ref(func, _cb)
63 self._meth_type = type(meth)
64 self._alive = True
65 self_wr = ref(self)
66 return self
68 def __call__(self):
70 func = self._func_ref()
73 return self._meth_type(func, obj)
75 def __eq__(self, other):
77 if not self._alive or not other._alive:
78 return self is other
79 return ref.__eq__(self, other) and self._func_ref == other._func_ref
82 def __ne__(self, other):
84 if not self._alive or not other._alive:
85 return self is not other
86 return ref.__ne__(self, other) or self._func_ref != other._func_ref
104 def __init__(self, other=(), /, **kw):
105 def remove(wr, selfref=ref(self), _atomic_removal=_remove_dead_weakref):
106 self = selfref()
107 if self is not None:
108 if self._iterating:
109 self._pending_removals.append(wr.key)
113 _atomic_removal(self.data, wr.key)
114 self._remove = remove
116 self._pending_removals = []
117 self._iterating = set()
118 self.data = {}
119 self.update(other, **kw)
121 def _commit_removals(self, _atomic_removal=_remove_dead_weakref):
122 pop = self._pending_removals.pop
123 d = self.data
133 def __getitem__(self, key):
134 if self._pending_removals:
135 self._commit_removals()
136 o = self.data[key]()
142 def __delitem__(self, key):
143 if self._pending_removals:
144 self._commit_removals()
145 del self.data[key]
147 def __len__(self):
148 if self._pending_removals:
149 self._commit_removals()
150 return len(self.data)
152 def __contains__(self, key):
153 if self._pending_removals:
154 self._commit_removals()
156 o = self.data[key]()
161 def __repr__(self):
162 return "<%s at %#x>" % (self.__class__.__name__, id(self))
164 def __setitem__(self, key, value):
165 if self._pending_removals:
166 self._commit_removals()
167 self.data[key] = KeyedRef(value, self._remove, key)
169 def copy(self):
170 if self._pending_removals:
171 self._commit_removals()
173 with _IterationGuard(self):
174 for key, wr in self.data.items():
182 def __deepcopy__(self, memo):
184 if self._pending_removals:
185 self._commit_removals()
186 new = self.__class__()
187 with _IterationGuard(self):
188 for key, wr in self.data.items():
194 def get(self, key, default=None):
195 if self._pending_removals:
196 self._commit_removals()
198 wr = self.data[key]
209 def items(self):
210 if self._pending_removals:
211 self._commit_removals()
212 with _IterationGuard(self):
213 for k, wr in self.data.items():
218 def keys(self):
219 if self._pending_removals:
220 self._commit_removals()
221 with _IterationGuard(self):
222 for k, wr in self.data.items():
228 def itervaluerefs(self):
238 if self._pending_removals:
239 self._commit_removals()
240 with _IterationGuard(self):
241 yield from self.data.values()
243 def values(self):
244 if self._pending_removals:
245 self._commit_removals()
246 with _IterationGuard(self):
247 for wr in self.data.values():
252 def popitem(self):
253 if self._pending_removals:
254 self._commit_removals()
256 key, wr = self.data.popitem()
261 def pop(self, key, *args):
262 if self._pending_removals:
263 self._commit_removals()
265 o = self.data.pop(key)()
276 def setdefault(self, key, default=None):
278 o = self.data[key]()
282 if self._pending_removals:
283 self._commit_removals()
284 self.data[key] = KeyedRef(default, self._remove, key)
289 def update(self, other=None, /, **kwargs):
290 if self._pending_removals:
291 self._commit_removals()
292 d = self.data
297 d[key] = KeyedRef(o, self._remove, key)
299 d[key] = KeyedRef(o, self._remove, key)
301 def valuerefs(self):
311 if self._pending_removals:
312 self._commit_removals()
313 return list(self.data.values())
315 def __ior__(self, other):
316 self.update(other)
317 return self
319 def __or__(self, other):
321 c = self.copy()
326 def __ror__(self, other):
328 c = self.__class__()
330 c.update(self)
348 self = ref.__new__(type, ob, callback)
349 self.key = key
350 return self
352 def __init__(self, ob, callback, key):
367 def __init__(self, dict=None):
368 self.data = {}
369 def remove(k, selfref=ref(self)):
370 self = selfref()
371 if self is not None:
372 if self._iterating:
373 self._pending_removals.append(k)
376 del self.data[k]
379 self._remove = remove
381 self._pending_removals = []
382 self._iterating = set()
383 self._dirty_len = False
385 self.update(dict)
387 def _commit_removals(self):
392 pop = self._pending_removals.pop
393 d = self.data
405 def _scrub_removals(self):
406 d = self.data
407 self._pending_removals = [k for k in self._pending_removals if k in d]
408 self._dirty_len = False
410 def __delitem__(self, key):
411 self._dirty_len = True
412 del self.data[ref(key)]
414 def __getitem__(self, key):
415 return self.data[ref(key)]
417 def __len__(self):
418 if self._dirty_len and self._pending_removals:
419 # self._pending_removals may still contain keys which were
421 self._scrub_removals()
422 return len(self.data) - len(self._pending_removals)
424 def __repr__(self):
425 return "<%s at %#x>" % (self.__class__.__name__, id(self))
427 def __setitem__(self, key, value):
428 self.data[ref(key, self._remove)] = value
430 def copy(self):
432 with _IterationGuard(self):
433 for key, value in self.data.items():
441 def __deepcopy__(self, memo):
443 new = self.__class__()
444 with _IterationGuard(self):
445 for key, value in self.data.items():
451 def get(self, key, default=None):
452 return self.data.get(ref(key),default)
454 def __contains__(self, key):
459 return wr in self.data
461 def items(self):
462 with _IterationGuard(self):
463 for wr, value in self.data.items():
468 def keys(self):
469 with _IterationGuard(self):
470 for wr in self.data:
477 def values(self):
478 with _IterationGuard(self):
479 for wr, value in self.data.items():
483 def keyrefs(self):
493 return list(self.data)
495 def popitem(self):
496 self._dirty_len = True
498 key, value = self.data.popitem()
503 def pop(self, key, *args):
504 self._dirty_len = True
505 return self.data.pop(ref(key), *args)
507 def setdefault(self, key, default=None):
508 return self.data.setdefault(ref(key, self._remove),default)
510 def update(self, dict=None, /, **kwargs):
511 d = self.data
516 d[ref(key, self._remove)] = value
518 self.update(kwargs)
520 def __ior__(self, other):
521 self.update(other)
522 return self
524 def __or__(self, other):
526 c = self.copy()
531 def __ror__(self, other):
533 c = self.__class__()
535 c.update(self)
568 def __init__(self, obj, func, /, *args, **kwargs):
569 if not self._registered_with_atexit:
573 atexit.register(self._exitfunc)
575 info = self._Info()
576 info.weakref = ref(obj, self)
581 info.index = next(self._index_iter)
582 self._registry[self] = info
585 def __call__(self, _=None):
588 info = self._registry.pop(self, None)
589 if info and not self._shutdown:
592 def detach(self):
595 info = self._registry.get(self)
597 if obj is not None and self._registry.pop(self, None):
600 def peek(self):
603 info = self._registry.get(self)
609 def alive(self):
611 return self in self._registry
614 def atexit(self):
616 info = self._registry.get(self)
620 def atexit(self, value):
621 info = self._registry.get(self)
625 def __repr__(self):
626 info = self._registry.get(self)
629 return '<%s object at %#x; dead>' % (type(self).__name__, id(self))
632 (type(self).__name__, id(self), type(obj).__name__, id(obj))