A writable placeholder for an unloaded collection. Stores items appended to and removed from a collection that has not yet been loaded. When the collection is loaded, the changes stored in PendingCollection are applied to it to produce the final result.
| 1142 | |
| 1143 | |
| 1144 | class PendingCollection: |
| 1145 | """A writable placeholder for an unloaded collection. |
| 1146 | |
| 1147 | Stores items appended to and removed from a collection that has not yet |
| 1148 | been loaded. When the collection is loaded, the changes stored in |
| 1149 | PendingCollection are applied to it to produce the final result. |
| 1150 | |
| 1151 | """ |
| 1152 | |
| 1153 | __slots__ = ("deleted_items", "added_items") |
| 1154 | |
| 1155 | deleted_items: util.IdentitySet |
| 1156 | added_items: util.OrderedIdentitySet |
| 1157 | |
| 1158 | def __init__(self) -> None: |
| 1159 | self.deleted_items = util.IdentitySet() |
| 1160 | self.added_items = util.OrderedIdentitySet() |
| 1161 | |
| 1162 | def merge_with_history(self, history: History) -> History: |
| 1163 | return history._merge(self.added_items, self.deleted_items) |
| 1164 | |
| 1165 | def append(self, value: Any) -> None: |
| 1166 | if value in self.deleted_items: |
| 1167 | self.deleted_items.remove(value) |
| 1168 | else: |
| 1169 | self.added_items.add(value) |
| 1170 | |
| 1171 | def remove(self, value: Any) -> None: |
| 1172 | if value in self.added_items: |
| 1173 | self.added_items.remove(value) |
| 1174 | else: |
| 1175 | self.deleted_items.add(value) |
no outgoing calls
no test coverage detected