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

Commit

Permalink
Type defintions for use in refactoring for redaction changes (#6803)
Browse files Browse the repository at this point in the history
* commit '5a246611e':
  Type defintions for use in refactoring for redaction changes (#6803)
  • Loading branch information
anoadragon453 committed Mar 23, 2020
2 parents 1310c64 + 5a24661 commit 45b330d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/6803.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactoring work in preparation for changing the event redaction algorithm.
5 changes: 3 additions & 2 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from synapse.api.errors import UnsupportedRoomVersionError
from synapse.api.room_versions import KNOWN_ROOM_VERSIONS, EventFormatVersions
from synapse.types import JsonDict
from synapse.util.caches import intern_dict
from synapse.util.frozenutils import freeze

Expand Down Expand Up @@ -197,7 +198,7 @@ def membership(self):
def is_state(self):
return hasattr(self, "state_key") and self.state_key is not None

def get_dict(self):
def get_dict(self) -> JsonDict:
d = dict(self._event_dict)
d.update({"signatures": self.signatures, "unsigned": dict(self.unsigned)})

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

def get_pdu_json(self, time_now=None):
def get_pdu_json(self, time_now=None) -> JsonDict:
pdu_json = self.get_dict()

if time_now is not None and "age_ts" in pdu_json["unsigned"]:
Expand Down
4 changes: 3 additions & 1 deletion synapse/python_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2017 Vector Creations Ltd
# Copyright 2018 New Vector Ltd
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +44,8 @@
"frozendict>=1",
"unpaddedbase64>=1.1.0",
"canonicaljson>=1.1.3",
"signedjson>=1.0.0",
# we use the type definitions added in signedjson 1.1.
"signedjson>=1.1.0",
"pynacl>=1.2.1",
"idna>=2.5",
# validating SSL certs for IP addresses requires service_identity 18.1.
Expand Down
7 changes: 6 additions & 1 deletion synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import string
import sys
from collections import namedtuple
from typing import Dict, Tuple, TypeVar
from typing import Any, Dict, Tuple, TypeVar

from six.moves import filter

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


# the type of a JSON-serialisable dict. This could be made stronger, but it will
# do for now.
JsonDict = Dict[str, Any]


class Requester(
namedtuple(
"Requester", ["user", "access_token_id", "is_guest", "device_id", "app_service"]
Expand Down

0 comments on commit 45b330d

Please sign in to comment.