-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Annotations for state_deltas.py #11316
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add type hints to storage classes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,17 @@ | |
from typing import Any, Dict, List, Tuple | ||
|
||
from synapse.storage._base import SQLBaseStore | ||
from synapse.storage.database import LoggingTransaction | ||
from synapse.util.caches.stream_change_cache import StreamChangeCache | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class StateDeltasStore(SQLBaseStore): | ||
# This class must be mixed in with a child class which provides the following | ||
# attribute. TODO: can we get static analysis to enforce this? | ||
_curr_state_delta_stream_cache: StreamChangeCache | ||
Comment on lines
25
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this an abstract class perhaps, with this being an abstract.. field... if that exists ... It doesn't seem like it does, but I would be tempted to try an abstract property: @property
@abstractmethod
def _curr_state_delta_stream_cache(self) -> StreamChangeCache:
... Not super clean, but curious if that'd do the trick (and if it's allowed to just overwrite it with a field later) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got
after
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might be interested in the discussion here: python/mypy#4426 |
||
|
||
async def get_current_state_deltas( | ||
self, prev_stream_id: int, max_stream_id: int | ||
) -> Tuple[int, List[Dict[str, Any]]]: | ||
|
@@ -60,7 +66,9 @@ async def get_current_state_deltas( | |
# max_stream_id. | ||
return max_stream_id, [] | ||
|
||
def get_current_state_deltas_txn(txn): | ||
def get_current_state_deltas_txn( | ||
txn: LoggingTransaction, | ||
) -> Tuple[int, List[Dict[str, Any]]]: | ||
# First we calculate the max stream id that will give us less than | ||
# N results. | ||
# We arbitrarily limit to 100 stream_id entries to ensure we don't | ||
|
@@ -106,15 +114,17 @@ def get_current_state_deltas_txn(txn): | |
"get_current_state_deltas", get_current_state_deltas_txn | ||
) | ||
|
||
def _get_max_stream_id_in_current_state_deltas_txn(self, txn): | ||
def _get_max_stream_id_in_current_state_deltas_txn( | ||
self, txn: LoggingTransaction | ||
) -> int: | ||
return self.db_pool.simple_select_one_onecol_txn( | ||
txn, | ||
table="current_state_delta_stream", | ||
keyvalues={}, | ||
retcol="COALESCE(MAX(stream_id), -1)", | ||
) | ||
|
||
async def get_max_stream_id_in_current_state_deltas(self): | ||
async def get_max_stream_id_in_current_state_deltas(self) -> int: | ||
return await self.db_pool.runInteraction( | ||
"get_max_stream_id_in_current_state_deltas", | ||
self._get_max_stream_id_in_current_state_deltas_txn, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #11322 instead. 😄