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

Commit fe58672

Browse files
author
David Robertson
authored
Annotations for state_deltas.py (#11316)
I was sad that I couldn't do better for `_curr_state_delta_stream_cache`. At least it's explicitly called out in a comment with #TODO.
1 parent 3fad4e3 commit fe58672

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

changelog.d/11316.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add type hints to storage classes.

mypy.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ exclude = (?x)
4747
|synapse/storage/databases/main/roommember.py
4848
|synapse/storage/databases/main/search.py
4949
|synapse/storage/databases/main/state.py
50-
|synapse/storage/databases/main/state_deltas.py
5150
|synapse/storage/databases/main/stats.py
5251
|synapse/storage/databases/main/transactions.py
5352
|synapse/storage/databases/main/user_directory.py
@@ -181,6 +180,9 @@ disallow_untyped_defs = True
181180
[mypy-synapse.storage.databases.main.room_batch]
182181
disallow_untyped_defs = True
183182

183+
[mypy-synapse.storage.databases.main.state_deltas]
184+
disallow_untyped_defs = True
185+
184186
[mypy-synapse.storage.databases.main.user_erasure_store]
185187
disallow_untyped_defs = True
186188

synapse/storage/databases/main/state_deltas.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
from typing import Any, Dict, List, Tuple
1717

1818
from synapse.storage._base import SQLBaseStore
19+
from synapse.storage.database import LoggingTransaction
20+
from synapse.util.caches.stream_change_cache import StreamChangeCache
1921

2022
logger = logging.getLogger(__name__)
2123

2224

2325
class StateDeltasStore(SQLBaseStore):
26+
# This class must be mixed in with a child class which provides the following
27+
# attribute. TODO: can we get static analysis to enforce this?
28+
_curr_state_delta_stream_cache: StreamChangeCache
29+
2430
async def get_current_state_deltas(
2531
self, prev_stream_id: int, max_stream_id: int
2632
) -> Tuple[int, List[Dict[str, Any]]]:
@@ -60,7 +66,9 @@ async def get_current_state_deltas(
6066
# max_stream_id.
6167
return max_stream_id, []
6268

63-
def get_current_state_deltas_txn(txn):
69+
def get_current_state_deltas_txn(
70+
txn: LoggingTransaction,
71+
) -> Tuple[int, List[Dict[str, Any]]]:
6472
# First we calculate the max stream id that will give us less than
6573
# N results.
6674
# We arbitrarily limit to 100 stream_id entries to ensure we don't
@@ -106,15 +114,17 @@ def get_current_state_deltas_txn(txn):
106114
"get_current_state_deltas", get_current_state_deltas_txn
107115
)
108116

109-
def _get_max_stream_id_in_current_state_deltas_txn(self, txn):
117+
def _get_max_stream_id_in_current_state_deltas_txn(
118+
self, txn: LoggingTransaction
119+
) -> int:
110120
return self.db_pool.simple_select_one_onecol_txn(
111121
txn,
112122
table="current_state_delta_stream",
113123
keyvalues={},
114124
retcol="COALESCE(MAX(stream_id), -1)",
115125
)
116126

117-
async def get_max_stream_id_in_current_state_deltas(self):
127+
async def get_max_stream_id_in_current_state_deltas(self) -> int:
118128
return await self.db_pool.runInteraction(
119129
"get_max_stream_id_in_current_state_deltas",
120130
self._get_max_stream_id_in_current_state_deltas_txn,

0 commit comments

Comments
 (0)