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

Commit 45b330d

Browse files
committed
Type defintions for use in refactoring for redaction changes (#6803)
* commit '5a246611e': Type defintions for use in refactoring for redaction changes (#6803)
2 parents 1310c64 + 5a24661 commit 45b330d

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

changelog.d/6803.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactoring work in preparation for changing the event redaction algorithm.

synapse/events/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from synapse.api.errors import UnsupportedRoomVersionError
2525
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, EventFormatVersions
26+
from synapse.types import JsonDict
2627
from synapse.util.caches import intern_dict
2728
from synapse.util.frozenutils import freeze
2829

@@ -197,7 +198,7 @@ def membership(self):
197198
def is_state(self):
198199
return hasattr(self, "state_key") and self.state_key is not None
199200

200-
def get_dict(self):
201+
def get_dict(self) -> JsonDict:
201202
d = dict(self._event_dict)
202203
d.update({"signatures": self.signatures, "unsigned": dict(self.unsigned)})
203204

@@ -209,7 +210,7 @@ def get(self, key, default=None):
209210
def get_internal_metadata_dict(self):
210211
return self.internal_metadata.get_dict()
211212

212-
def get_pdu_json(self, time_now=None):
213+
def get_pdu_json(self, time_now=None) -> JsonDict:
213214
pdu_json = self.get_dict()
214215

215216
if time_now is not None and "age_ts" in pdu_json["unsigned"]:

synapse/python_dependencies.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2015, 2016 OpenMarket Ltd
22
# Copyright 2017 Vector Creations Ltd
33
# Copyright 2018 New Vector Ltd
4+
# Copyright 2020 The Matrix.org Foundation C.I.C.
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
67
# you may not use this file except in compliance with the License.
@@ -43,7 +44,8 @@
4344
"frozendict>=1",
4445
"unpaddedbase64>=1.1.0",
4546
"canonicaljson>=1.1.3",
46-
"signedjson>=1.0.0",
47+
# we use the type definitions added in signedjson 1.1.
48+
"signedjson>=1.1.0",
4749
"pynacl>=1.2.1",
4850
"idna>=2.5",
4951
# validating SSL certs for IP addresses requires service_identity 18.1.

synapse/types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import string
1818
import sys
1919
from collections import namedtuple
20-
from typing import Dict, Tuple, TypeVar
20+
from typing import Any, Dict, Tuple, TypeVar
2121

2222
from six.moves import filter
2323

@@ -45,6 +45,11 @@ class Collection(Iterable[T_co], Container[T_co], Sized):
4545
StateMap = Dict[Tuple[str, str], T]
4646

4747

48+
# the type of a JSON-serialisable dict. This could be made stronger, but it will
49+
# do for now.
50+
JsonDict = Dict[str, Any]
51+
52+
4853
class Requester(
4954
namedtuple(
5055
"Requester", ["user", "access_token_id", "is_guest", "device_id", "app_service"]

0 commit comments

Comments
 (0)