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)
| 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 | """ |