MCPcopy
hub / github.com/ormar-orm/ormar / pop

Method pop

ormar/relations/relation_proxy.py:144–171  ·  view source on GitHub ↗

Pops the index off the list and returns it. By default, it pops off the element at index 0. This also clears the value from the relation cache. :param index: The index to pop :type index: SupportsIndex :return: The item at the provided index

(self, index: SupportsIndex = 0)

Source from the content-addressed store, hash-verified

142 return to_remove
143
144 def pop(self, index: SupportsIndex = 0) -> T:
145 """
146 Pops the index off the list and returns it. By default,
147 it pops off the element at index 0.
148 This also clears the value from the relation cache.
149
150 :param index: The index to pop
151 :type index: SupportsIndex
152 :return: The item at the provided index
153 :rtype: "T"
154 """
155 item = self[index]
156
157 # Try to delete it, but do it a long way
158 # if weakly-referenced thing doesn't exist
159 try:
160 self._relation_cache.pop(item.__hash__())
161 except ReferenceError:
162 for hash_, idx in self._relation_cache.items():
163 if idx == index:
164 self._relation_cache.pop(hash_)
165 break
166
167 index_int = int(index)
168 for idx in range(index_int + 1, len(self)):
169 self._relation_cache[self[idx].__hash__()] -= 1
170
171 return super().pop(index)
172
173 def __contains__(self, item: object) -> bool:
174 """

Callers 15

removeMethod · 0.95
before_relation_addFunction · 0.80
subtract_dictFunction · 0.80
update_or_createMethod · 0.80
prepare_filterMethod · 0.80
disconnectMethod · 0.80
update_cacheMethod · 0.80
createMethod · 0.80
updateMethod · 0.80
update_or_createMethod · 0.80
removeMethod · 0.80

Calls 1

__hash__Method · 0.45

Tested by 2

before_relation_addFunction · 0.64