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

Commit

Permalink
disallow-untyped-defs for synapse.state (#11004)
Browse files Browse the repository at this point in the history
* `disallow-untyped-defs` for `synapse.state`

Much smaller than I was expecting!
  • Loading branch information
David Robertson committed Oct 6, 2021
1 parent e564bdd commit f563676
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/11004.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add further type hints to `synapse.state`.
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ disallow_untyped_defs = True
[mypy-synapse.rest.*]
disallow_untyped_defs = True

[mypy-synapse.state.*]
disallow_untyped_defs = True

[mypy-synapse.util.batching_queue]
disallow_untyped_defs = True

Expand Down
2 changes: 1 addition & 1 deletion synapse/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(
else:
self.state_id = _gen_state_id()

def __len__(self):
def __len__(self) -> int:
return len(self.state)


Expand Down
4 changes: 2 additions & 2 deletions synapse/state/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _resolve_with_state(
conflicted_state_ids: StateMap[Set[str]],
auth_event_ids: StateMap[str],
state_map: Dict[str, EventBase],
):
) -> MutableStateMap[str]:
conflicted_state = {}
for key, event_ids in conflicted_state_ids.items():
events = [state_map[ev_id] for ev_id in event_ids if ev_id in state_map]
Expand Down Expand Up @@ -362,7 +362,7 @@ def _resolve_normal_events(


def _ordered_events(events: Iterable[EventBase]) -> List[EventBase]:
def key_func(e):
def key_func(e: EventBase) -> Tuple[int, str]:
# we have to use utf-8 rather than ascii here because it turns out we allow
# people to send us events with non-ascii event IDs :/
return -int(e.depth), hashlib.sha1(e.event_id.encode("utf-8")).hexdigest()
Expand Down
2 changes: 1 addition & 1 deletion synapse/state/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ async def _reverse_topological_power_sort(
if idx % _AWAIT_AFTER_ITERATIONS == 0:
await clock.sleep(0)

def _get_power_order(event_id):
def _get_power_order(event_id: str) -> Tuple[int, int, str]:
ev = event_map[event_id]
pl = event_to_pl[event_id]

Expand Down

0 comments on commit f563676

Please sign in to comment.