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

Commit f563676

Browse files
author
David Robertson
authored
disallow-untyped-defs for synapse.state (#11004)
* `disallow-untyped-defs` for `synapse.state` Much smaller than I was expecting!
1 parent e564bdd commit f563676

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

changelog.d/11004.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add further type hints to `synapse.state`.

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ disallow_untyped_defs = True
9999
[mypy-synapse.rest.*]
100100
disallow_untyped_defs = True
101101

102+
[mypy-synapse.state.*]
103+
disallow_untyped_defs = True
104+
102105
[mypy-synapse.util.batching_queue]
103106
disallow_untyped_defs = True
104107

synapse/state/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __init__(
118118
else:
119119
self.state_id = _gen_state_id()
120120

121-
def __len__(self):
121+
def __len__(self) -> int:
122122
return len(self.state)
123123

124124

synapse/state/v1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _resolve_with_state(
225225
conflicted_state_ids: StateMap[Set[str]],
226226
auth_event_ids: StateMap[str],
227227
state_map: Dict[str, EventBase],
228-
):
228+
) -> MutableStateMap[str]:
229229
conflicted_state = {}
230230
for key, event_ids in conflicted_state_ids.items():
231231
events = [state_map[ev_id] for ev_id in event_ids if ev_id in state_map]
@@ -362,7 +362,7 @@ def _resolve_normal_events(
362362

363363

364364
def _ordered_events(events: Iterable[EventBase]) -> List[EventBase]:
365-
def key_func(e):
365+
def key_func(e: EventBase) -> Tuple[int, str]:
366366
# we have to use utf-8 rather than ascii here because it turns out we allow
367367
# people to send us events with non-ascii event IDs :/
368368
return -int(e.depth), hashlib.sha1(e.event_id.encode("utf-8")).hexdigest()

synapse/state/v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ async def _reverse_topological_power_sort(
481481
if idx % _AWAIT_AFTER_ITERATIONS == 0:
482482
await clock.sleep(0)
483483

484-
def _get_power_order(event_id):
484+
def _get_power_order(event_id: str) -> Tuple[int, int, str]:
485485
ev = event_map[event_id]
486486
pl = event_to_pl[event_id]
487487

0 commit comments

Comments
 (0)