summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-12-08 19:02:13 +0000
committerAndrew Morgan <andrew@amorgan.xyz>2021-12-09 17:53:39 +0000
commit0f9a425797a39f947d59337364a70f7529f78640 (patch)
tree754f0290bf3ba23fefbc487d666d8a7f985ad848
parentMove DeviceLists type to synapse.types (diff)
downloadsynapse-0f9a425797a39f947d59337364a70f7529f78640.tar.xz
Switch DeviceLists to containing Sets, as we'll need a type that we can delete items from
-rw-r--r--synapse/handlers/sync.py2
-rw-r--r--synapse/types.py12
2 files changed, 9 insertions, 5 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 025eb82434..ebe6fac388 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -1305,7 +1305,7 @@ class SyncHandler:
 
             return DeviceLists(changed=users_that_have_changed, left=newly_left_users)
         else:
-            return DeviceLists(changed=[], left=[])
+            return DeviceLists()
 
     async def _generate_sync_entry_for_to_device(
         self, sync_result_builder: "SyncResultBuilder"
diff --git a/synapse/types.py b/synapse/types.py
index 7346498f61..0355b959f0 100644
--- a/synapse/types.py
+++ b/synapse/types.py
@@ -20,11 +20,11 @@ from typing import (
     TYPE_CHECKING,
     Any,
     ClassVar,
-    Collection,
     Dict,
     Mapping,
     MutableMapping,
     Optional,
+    Set,
     Tuple,
     Type,
     TypeVar,
@@ -759,9 +759,13 @@ class DeviceLists:
         changed: List of user_ids whose devices may have changed
         left: List of user_ids whose devices we no longer track
     """
-
-    changed: Collection[str]
-    left: Collection[str]
+    # We need to use a factory here, otherwise `set` is not evaluated at
+    # object instantiation, but instead at class definition instantiation.
+    # The latter happening only once, thus always giving you the same sets
+    # across multiple DeviceLists instances.
+    # Also see: don't define mutable default arguments.
+    changed: Set[str] = attr.ib(factory=set)
+    left: Set[str] = attr.ib(factory=set)
 
     def __bool__(self) -> bool:
         return bool(self.changed or self.left)