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

Commit

Permalink
Switch metaclass initialization to python 3-compatible syntax (#8326)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowJonathan authored Sep 16, 2020
1 parent 44dec6c commit a3f124b
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 26 deletions.
1 change: 1 addition & 0 deletions changelog.d/8326.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update outdated usages of `metaclass` to python 3 syntax.
4 changes: 1 addition & 3 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@
logger = logging.getLogger(__name__)


class RoomMemberHandler:
class RoomMemberHandler(metaclass=abc.ABCMeta):
# TODO(paul): This handler currently contains a messy conflation of
# low-level API that works on UserID objects and so on, and REST-level
# API that takes ID strings and returns pagination chunks. These concerns
# ought to be separated out a lot better.

__metaclass__ = abc.ABCMeta

def __init__(self, hs: "HomeServer"):
self.hs = hs
self.store = hs.get_datastore()
Expand Down
4 changes: 1 addition & 3 deletions synapse/replication/http/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
logger = logging.getLogger(__name__)


class ReplicationEndpoint:
class ReplicationEndpoint(metaclass=abc.ABCMeta):
"""Helper base class for defining new replication HTTP endpoints.
This creates an endpoint under `/_synapse/replication/:NAME/:PATH_ARGS..`
Expand Down Expand Up @@ -72,8 +72,6 @@ class ReplicationEndpoint:
is received.
"""

__metaclass__ = abc.ABCMeta

NAME = abc.abstractproperty() # type: str # type: ignore
PATH_ARGS = abc.abstractproperty() # type: Tuple[str, ...] # type: ignore
METHOD = "POST"
Expand Down
8 changes: 3 additions & 5 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@
logger = logging.getLogger(__name__)


class AccountDataWorkerStore(SQLBaseStore):
# The ABCMeta metaclass ensures that it cannot be instantiated without
# the abstract methods being implemented.
class AccountDataWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta):
"""This is an abstract base class where subclasses must implement
`get_max_account_data_stream_id` which can be called in the initializer.
"""

# This ABCMeta metaclass ensures that we cannot be instantiated without
# the abstract methods being implemented.
__metaclass__ = abc.ABCMeta

def __init__(self, database: DatabasePool, db_conn, hs):
account_max = self.get_max_account_data_stream_id()
self._account_data_stream_cache = StreamChangeCache(
Expand Down
7 changes: 3 additions & 4 deletions synapse/storage/databases/main/push_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,21 @@ def _load_rules(rawrules, enabled_map, use_new_defaults=False):
return rules


# The ABCMeta metaclass ensures that it cannot be instantiated without
# the abstract methods being implemented.
class PushRulesWorkerStore(
ApplicationServiceWorkerStore,
ReceiptsWorkerStore,
PusherWorkerStore,
RoomMemberWorkerStore,
EventsWorkerStore,
SQLBaseStore,
metaclass=abc.ABCMeta,
):
"""This is an abstract base class where subclasses must implement
`get_max_push_rules_stream_id` which can be called in the initializer.
"""

# This ABCMeta metaclass ensures that we cannot be instantiated without
# the abstract methods being implemented.
__metaclass__ = abc.ABCMeta

def __init__(self, database: DatabasePool, db_conn, hs):
super(PushRulesWorkerStore, self).__init__(database, db_conn, hs)

Expand Down
8 changes: 3 additions & 5 deletions synapse/storage/databases/main/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
logger = logging.getLogger(__name__)


class ReceiptsWorkerStore(SQLBaseStore):
# The ABCMeta metaclass ensures that it cannot be instantiated without
# the abstract methods being implemented.
class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta):
"""This is an abstract base class where subclasses must implement
`get_max_receipt_stream_id` which can be called in the initializer.
"""

# This ABCMeta metaclass ensures that we cannot be instantiated without
# the abstract methods being implemented.
__metaclass__ = abc.ABCMeta

def __init__(self, database: DatabasePool, db_conn, hs):
super(ReceiptsWorkerStore, self).__init__(database, db_conn, hs)

Expand Down
4 changes: 1 addition & 3 deletions synapse/storage/databases/main/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,12 @@ def filter_to_clause(event_filter: Optional[Filter]) -> Tuple[str, List[str]]:
return " AND ".join(clauses), args


class StreamWorkerStore(EventsWorkerStore, SQLBaseStore):
class StreamWorkerStore(EventsWorkerStore, SQLBaseStore, metaclass=abc.ABCMeta):
"""This is an abstract base class where subclasses must implement
`get_room_max_stream_ordering` and `get_room_min_stream_ordering`
which can be called in the initializer.
"""

__metaclass__ = abc.ABCMeta

def __init__(self, database: DatabasePool, db_conn, hs: "HomeServer"):
super(StreamWorkerStore, self).__init__(database, db_conn, hs)

Expand Down
6 changes: 3 additions & 3 deletions synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def get_localpart_from_id(string):
DS = TypeVar("DS", bound="DomainSpecificString")


class DomainSpecificString(namedtuple("DomainSpecificString", ("localpart", "domain"))):
class DomainSpecificString(
namedtuple("DomainSpecificString", ("localpart", "domain")), metaclass=abc.ABCMeta
):
"""Common base class among ID/name strings that have a local part and a
domain name, prefixed with a sigil.
Expand All @@ -175,8 +177,6 @@ class DomainSpecificString(namedtuple("DomainSpecificString", ("localpart", "dom
'domain' : The domain part of the name
"""

__metaclass__ = abc.ABCMeta

SIGIL = abc.abstractproperty() # type: str # type: ignore

# Deny iteration because it will bite you if you try to create a singleton
Expand Down

0 comments on commit a3f124b

Please sign in to comment.