11# Copyright 2014-2016 OpenMarket Ltd
2+ # Copyright 2021 The Matrix.org Foundation C.I.C.
23#
34# Licensed under the Apache License, Version 2.0 (the "License");
45# you may not use this file except in compliance with the License.
@@ -350,7 +351,7 @@ class BaseFederationRow:
350351 TypeId = "" # Unique string that ids the type. Must be overridden in sub classes.
351352
352353 @staticmethod
353- def from_data (data ) :
354+ def from_data (data : JsonDict ) -> "BaseFederationRow" :
354355 """Parse the data from the federation stream into a row.
355356
356357 Args:
@@ -359,7 +360,7 @@ def from_data(data):
359360 """
360361 raise NotImplementedError ()
361362
362- def to_data (self ):
363+ def to_data (self ) -> JsonDict :
363364 """Serialize this row to be sent over the federation stream.
364365
365366 Returns:
@@ -368,7 +369,7 @@ def to_data(self):
368369 """
369370 raise NotImplementedError ()
370371
371- def add_to_buffer (self , buff ) :
372+ def add_to_buffer (self , buff : "ParsedFederationStreamData" ) -> None :
372373 """Add this row to the appropriate field in the buffer ready for this
373374 to be sent over federation.
374375
@@ -391,15 +392,15 @@ class PresenceDestinationsRow(
391392 TypeId = "pd"
392393
393394 @staticmethod
394- def from_data (data ) :
395+ def from_data (data : JsonDict ) -> "PresenceDestinationsRow" :
395396 return PresenceDestinationsRow (
396397 state = UserPresenceState .from_dict (data ["state" ]), destinations = data ["dests" ]
397398 )
398399
399- def to_data (self ):
400+ def to_data (self ) -> JsonDict :
400401 return {"state" : self .state .as_dict (), "dests" : self .destinations }
401402
402- def add_to_buffer (self , buff ) :
403+ def add_to_buffer (self , buff : "ParsedFederationStreamData" ) -> None :
403404 buff .presence_destinations .append ((self .state , self .destinations ))
404405
405406
@@ -417,13 +418,13 @@ class KeyedEduRow(
417418 TypeId = "k"
418419
419420 @staticmethod
420- def from_data (data ) :
421+ def from_data (data : JsonDict ) -> "KeyedEduRow" :
421422 return KeyedEduRow (key = tuple (data ["key" ]), edu = Edu (** data ["edu" ]))
422423
423- def to_data (self ):
424+ def to_data (self ) -> JsonDict :
424425 return {"key" : self .key , "edu" : self .edu .get_internal_dict ()}
425426
426- def add_to_buffer (self , buff ) :
427+ def add_to_buffer (self , buff : "ParsedFederationStreamData" ) -> None :
427428 buff .keyed_edus .setdefault (self .edu .destination , {})[self .key ] = self .edu
428429
429430
@@ -433,13 +434,13 @@ class EduRow(BaseFederationRow, namedtuple("EduRow", ("edu",))): # Edu
433434 TypeId = "e"
434435
435436 @staticmethod
436- def from_data (data ) :
437+ def from_data (data : JsonDict ) -> "EduRow" :
437438 return EduRow (Edu (** data ))
438439
439- def to_data (self ):
440+ def to_data (self ) -> JsonDict :
440441 return self .edu .get_internal_dict ()
441442
442- def add_to_buffer (self , buff ) :
443+ def add_to_buffer (self , buff : "ParsedFederationStreamData" ) -> None :
443444 buff .edus .setdefault (self .edu .destination , []).append (self .edu )
444445
445446
0 commit comments