Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

add __bool__ alias to __nonzero__ methods #3107

Merged
merged 1 commit into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __nonzero__(self):
to tell if room needs to be part of the sync result.
"""
return bool(self.events)
__bool__ = __nonzero__ # python3


class JoinedSyncResult(collections.namedtuple("JoinedSyncResult", [
Expand All @@ -76,6 +77,7 @@ def __nonzero__(self):
# nb the notification count does not, er, count: if there's nothing
# else in the result, we don't need to send it.
)
__bool__ = __nonzero__ # python3


class ArchivedSyncResult(collections.namedtuple("ArchivedSyncResult", [
Expand All @@ -95,6 +97,7 @@ def __nonzero__(self):
or self.state
or self.account_data
)
__bool__ = __nonzero__ # python3


class InvitedSyncResult(collections.namedtuple("InvitedSyncResult", [
Expand All @@ -106,6 +109,7 @@ class InvitedSyncResult(collections.namedtuple("InvitedSyncResult", [
def __nonzero__(self):
"""Invited rooms should always be reported to the client"""
return True
__bool__ = __nonzero__ # python3


class GroupsSyncResult(collections.namedtuple("GroupsSyncResult", [
Expand All @@ -117,6 +121,7 @@ class GroupsSyncResult(collections.namedtuple("GroupsSyncResult", [

def __nonzero__(self):
return bool(self.join or self.invite or self.leave)
__bool__ = __nonzero__ # python3


class DeviceLists(collections.namedtuple("DeviceLists", [
Expand All @@ -127,6 +132,7 @@ class DeviceLists(collections.namedtuple("DeviceLists", [

def __nonzero__(self):
return bool(self.changed or self.left)
__bool__ = __nonzero__ # python3


class SyncResult(collections.namedtuple("SyncResult", [
Expand Down Expand Up @@ -159,6 +165,7 @@ def __nonzero__(self):
self.device_lists or
self.groups
)
__bool__ = __nonzero__ # python3


class SyncHandler(object):
Expand Down
1 change: 1 addition & 0 deletions synapse/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def new_listener(self, token):
class EventStreamResult(namedtuple("EventStreamResult", ("events", "tokens"))):
def __nonzero__(self):
return bool(self.events)
__bool__ = __nonzero__ # python3


class Notifier(object):
Expand Down
1 change: 1 addition & 0 deletions synapse/util/logcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def add_database_scheduled(self, sched_ms):

def __nonzero__(self):
return False
__bool__ = __nonzero__ # python3

sentinel = Sentinel()

Expand Down