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

Commit b2cd3b8

Browse files
committed
Make _account_data_id_gen always an AbstractStreamIdGenerator to appease mypy
As get_next_txn is part of AbstractStreamIdGenerator, not AbstractStreamIdTracker. I'm not sure why we insisted in trying to type it as a Tracker vs. a Generator, and then checking that elsewhere in the codebase. The init function of AccountDataWorkerStore will always create _account_data_id_gen as either a StreamIdGenerator or a MultiWriterIdGenerator. Both of which are AbstractStreamidGenerators.
1 parent ae14dfc commit b2cd3b8

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

synapse/storage/databases/main/account_data.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from synapse.storage.engines import PostgresEngine
4040
from synapse.storage.util.id_generators import (
4141
AbstractStreamIdGenerator,
42-
AbstractStreamIdTracker,
4342
MultiWriterIdGenerator,
4443
StreamIdGenerator,
4544
)
@@ -63,14 +62,12 @@ def __init__(
6362
):
6463
super().__init__(database, db_conn, hs)
6564

66-
# `_can_write_to_account_data` indicates whether the current worker is allowed
67-
# to write account data. A value of `True` implies that `_account_data_id_gen`
68-
# is an `AbstractStreamIdGenerator` and not just a tracker.
69-
self._account_data_id_gen: AbstractStreamIdTracker
7065
self._can_write_to_account_data = (
7166
self._instance_name in hs.config.worker.writers.account_data
7267
)
7368

69+
self._account_data_id_gen: AbstractStreamIdGenerator
70+
7471
if isinstance(database.engine, PostgresEngine):
7572
self._account_data_id_gen = MultiWriterIdGenerator(
7673
db_conn=db_conn,
@@ -475,7 +472,6 @@ async def add_account_data_to_room(
475472
The maximum stream ID.
476473
"""
477474
assert self._can_write_to_account_data
478-
assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator)
479475

480476
content_json = json_encoder.encode(content)
481477

@@ -514,7 +510,6 @@ async def remove_account_data_for_room(
514510
The maximum account data stream position.
515511
"""
516512
assert self._can_write_to_account_data
517-
assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator)
518513

519514
def _remove_account_data_for_room_txn(txn: LoggingTransaction) -> Optional[int]:
520515
"""
@@ -590,7 +585,6 @@ async def add_account_data_for_user(
590585
The maximum stream ID.
591586
"""
592587
assert self._can_write_to_account_data
593-
assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator)
594588

595589
async with self._account_data_id_gen.get_next() as next_id:
596590
await self.db_pool.runInteraction(
@@ -696,7 +690,6 @@ async def remove_account_data_for_user(
696690
The maximum account data stream position.
697691
"""
698692
assert self._can_write_to_account_data
699-
assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator)
700693

701694
def _remove_account_data_for_user_txn(txn: LoggingTransaction) -> Optional[int]:
702695
"""

0 commit comments

Comments
 (0)