@@ -89,14 +89,12 @@ class TimelineBatch:
89
89
events = attr .ib (type = List [EventBase ])
90
90
limited = attr .ib (bool )
91
91
92
- def __nonzero__ (self ) -> bool :
92
+ def __bool__ (self ) -> bool :
93
93
"""Make the result appear empty if there are no updates. This is used
94
94
to tell if room needs to be part of the sync result.
95
95
"""
96
96
return bool (self .events )
97
97
98
- __bool__ = __nonzero__ # python3
99
-
100
98
101
99
# We can't freeze this class, because we need to update it after it's instantiated to
102
100
# update its unread count. This is because we calculate the unread count for a room only
@@ -114,7 +112,7 @@ class JoinedSyncResult:
114
112
summary = attr .ib (type = Optional [JsonDict ])
115
113
unread_count = attr .ib (type = int )
116
114
117
- def __nonzero__ (self ) -> bool :
115
+ def __bool__ (self ) -> bool :
118
116
"""Make the result appear empty if there are no updates. This is used
119
117
to tell if room needs to be part of the sync result.
120
118
"""
@@ -127,8 +125,6 @@ def __nonzero__(self) -> bool:
127
125
# else in the result, we don't need to send it.
128
126
)
129
127
130
- __bool__ = __nonzero__ # python3
131
-
132
128
133
129
@attr .s (slots = True , frozen = True )
134
130
class ArchivedSyncResult :
@@ -137,38 +133,32 @@ class ArchivedSyncResult:
137
133
state = attr .ib (type = StateMap [EventBase ])
138
134
account_data = attr .ib (type = List [JsonDict ])
139
135
140
- def __nonzero__ (self ) -> bool :
136
+ def __bool__ (self ) -> bool :
141
137
"""Make the result appear empty if there are no updates. This is used
142
138
to tell if room needs to be part of the sync result.
143
139
"""
144
140
return bool (self .timeline or self .state or self .account_data )
145
141
146
- __bool__ = __nonzero__ # python3
147
-
148
142
149
143
@attr .s (slots = True , frozen = True )
150
144
class InvitedSyncResult :
151
145
room_id = attr .ib (type = str )
152
146
invite = attr .ib (type = EventBase )
153
147
154
- def __nonzero__ (self ) -> bool :
148
+ def __bool__ (self ) -> bool :
155
149
"""Invited rooms should always be reported to the client"""
156
150
return True
157
151
158
- __bool__ = __nonzero__ # python3
159
-
160
152
161
153
@attr .s (slots = True , frozen = True )
162
154
class GroupsSyncResult :
163
155
join = attr .ib (type = JsonDict )
164
156
invite = attr .ib (type = JsonDict )
165
157
leave = attr .ib (type = JsonDict )
166
158
167
- def __nonzero__ (self ) -> bool :
159
+ def __bool__ (self ) -> bool :
168
160
return bool (self .join or self .invite or self .leave )
169
161
170
- __bool__ = __nonzero__ # python3
171
-
172
162
173
163
@attr .s (slots = True , frozen = True )
174
164
class DeviceLists :
@@ -181,13 +171,11 @@ class DeviceLists:
181
171
changed = attr .ib (type = Collection [str ])
182
172
left = attr .ib (type = Collection [str ])
183
173
184
- def __nonzero__ (self ) -> bool :
174
+ def __bool__ (self ) -> bool :
185
175
return bool (self .changed or self .left )
186
176
187
- __bool__ = __nonzero__ # python3
188
177
189
-
190
- @attr .s
178
+ @attr .s (slots = True )
191
179
class _RoomChanges :
192
180
"""The set of room entries to include in the sync, plus the set of joined
193
181
and left room IDs since last sync.
@@ -227,7 +215,7 @@ class SyncResult:
227
215
device_one_time_keys_count = attr .ib (type = JsonDict )
228
216
groups = attr .ib (type = Optional [GroupsSyncResult ])
229
217
230
- def __nonzero__ (self ) -> bool :
218
+ def __bool__ (self ) -> bool :
231
219
"""Make the result appear empty if there are no updates. This is used
232
220
to tell if the notifier needs to wait for more events when polling for
233
221
events.
@@ -243,8 +231,6 @@ def __nonzero__(self) -> bool:
243
231
or self .groups
244
232
)
245
233
246
- __bool__ = __nonzero__ # python3
247
-
248
234
249
235
class SyncHandler :
250
236
def __init__ (self , hs : "HomeServer" ):
@@ -2038,7 +2024,7 @@ def _calculate_state(
2038
2024
return {event_id_to_key [e ]: e for e in state_ids }
2039
2025
2040
2026
2041
- @attr .s
2027
+ @attr .s ( slots = True )
2042
2028
class SyncResultBuilder :
2043
2029
"""Used to help build up a new SyncResult for a user
2044
2030
@@ -2074,7 +2060,7 @@ class SyncResultBuilder:
2074
2060
to_device = attr .ib (type = List [JsonDict ], default = attr .Factory (list ))
2075
2061
2076
2062
2077
- @attr .s
2063
+ @attr .s ( slots = True )
2078
2064
class RoomSyncResultBuilder :
2079
2065
"""Stores information needed to create either a `JoinedSyncResult` or
2080
2066
`ArchivedSyncResult`.
0 commit comments