mirror of
https://mau.dev/maunium/synapse.git
synced 2025-01-19 03:01:57 +01:00
disallow-untyped-defs
for synapse.state
(#11004)
* `disallow-untyped-defs` for `synapse.state` Much smaller than I was expecting!
This commit is contained in:
parent
e564bdd127
commit
f563676c09
5 changed files with 8 additions and 4 deletions
1
changelog.d/11004.misc
Normal file
1
changelog.d/11004.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Add further type hints to `synapse.state`.
|
3
mypy.ini
3
mypy.ini
|
@ -99,6 +99,9 @@ disallow_untyped_defs = True
|
||||||
[mypy-synapse.rest.*]
|
[mypy-synapse.rest.*]
|
||||||
disallow_untyped_defs = True
|
disallow_untyped_defs = True
|
||||||
|
|
||||||
|
[mypy-synapse.state.*]
|
||||||
|
disallow_untyped_defs = True
|
||||||
|
|
||||||
[mypy-synapse.util.batching_queue]
|
[mypy-synapse.util.batching_queue]
|
||||||
disallow_untyped_defs = True
|
disallow_untyped_defs = True
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ class _StateCacheEntry:
|
||||||
else:
|
else:
|
||||||
self.state_id = _gen_state_id()
|
self.state_id = _gen_state_id()
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self) -> int:
|
||||||
return len(self.state)
|
return len(self.state)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@ def _resolve_with_state(
|
||||||
conflicted_state_ids: StateMap[Set[str]],
|
conflicted_state_ids: StateMap[Set[str]],
|
||||||
auth_event_ids: StateMap[str],
|
auth_event_ids: StateMap[str],
|
||||||
state_map: Dict[str, EventBase],
|
state_map: Dict[str, EventBase],
|
||||||
):
|
) -> MutableStateMap[str]:
|
||||||
conflicted_state = {}
|
conflicted_state = {}
|
||||||
for key, event_ids in conflicted_state_ids.items():
|
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]
|
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(
|
||||||
|
|
||||||
|
|
||||||
def _ordered_events(events: Iterable[EventBase]) -> List[EventBase]:
|
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
|
# 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 :/
|
# people to send us events with non-ascii event IDs :/
|
||||||
return -int(e.depth), hashlib.sha1(e.event_id.encode("utf-8")).hexdigest()
|
return -int(e.depth), hashlib.sha1(e.event_id.encode("utf-8")).hexdigest()
|
||||||
|
|
|
@ -481,7 +481,7 @@ async def _reverse_topological_power_sort(
|
||||||
if idx % _AWAIT_AFTER_ITERATIONS == 0:
|
if idx % _AWAIT_AFTER_ITERATIONS == 0:
|
||||||
await clock.sleep(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]
|
ev = event_map[event_id]
|
||||||
pl = event_to_pl[event_id]
|
pl = event_to_pl[event_id]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue