STAR-322: Using findChanges method to simplify code

This commit is contained in:
Daniel Schiavini 2018-12-05 16:15:51 +01:00
parent 7e76913736
commit 657e763318
3 changed files with 27 additions and 24 deletions

View file

@ -4,6 +4,13 @@ T = TypeVar("T")
U = TypeVar("U")
## Splits the given dictionaries into three lists (in a tuple):
# - `removed`: Items that were in the first argument but removed in the second one.
# - `added`: Items that were not in the first argument but were included in the second one.
# - `updated`: Items that were in both dictionaries. Both values are given in a tuple.
# \param previous: The previous items
# \param received: The received items
# \return: The tuple (removed, added, updated) as explained above.
def findChanges(previous: Dict[str, T], received: Dict[str, U]) -> Tuple[List[T], List[U], List[Tuple[T, U]]]:
previous_ids = set(previous)
received_ids = set(received)