2929 Mapping ,
3030 Optional ,
3131 Tuple ,
32+ Type ,
3233 Union ,
3334 cast ,
3435)
@@ -439,7 +440,7 @@ async def _get_available_ui_auth_types(self, user: UserID) -> Iterable[str]:
439440
440441 return ui_auth_types
441442
442- def get_enabled_auth_types (self ):
443+ def get_enabled_auth_types (self ) -> Iterable [ str ] :
443444 """Return the enabled user-interactive authentication types
444445
445446 Returns the UI-Auth types which are supported by the homeserver's current
@@ -702,7 +703,7 @@ async def get_session_data(
702703 except StoreError :
703704 raise SynapseError (400 , "Unknown session ID: %s" % (session_id ,))
704705
705- async def _expire_old_sessions (self ):
706+ async def _expire_old_sessions (self ) -> None :
706707 """
707708 Invalidate any user interactive authentication sessions that have expired.
708709 """
@@ -1352,7 +1353,7 @@ async def validate_short_term_login_token(
13521353 await self .auth .check_auth_blocking (res .user_id )
13531354 return res
13541355
1355- async def delete_access_token (self , access_token : str ):
1356+ async def delete_access_token (self , access_token : str ) -> None :
13561357 """Invalidate a single access token
13571358
13581359 Args:
@@ -1381,7 +1382,7 @@ async def delete_access_tokens_for_user(
13811382 user_id : str ,
13821383 except_token_id : Optional [int ] = None ,
13831384 device_id : Optional [str ] = None ,
1384- ):
1385+ ) -> None :
13851386 """Invalidate access tokens belonging to a user
13861387
13871388 Args:
@@ -1409,7 +1410,7 @@ async def delete_access_tokens_for_user(
14091410
14101411 async def add_threepid (
14111412 self , user_id : str , medium : str , address : str , validated_at : int
1412- ):
1413+ ) -> None :
14131414 # check if medium has a valid value
14141415 if medium not in ["email" , "msisdn" ]:
14151416 raise SynapseError (
@@ -1480,7 +1481,7 @@ async def hash(self, password: str) -> str:
14801481 Hashed password.
14811482 """
14821483
1483- def _do_hash ():
1484+ def _do_hash () -> str :
14841485 # Normalise the Unicode in the password
14851486 pw = unicodedata .normalize ("NFKC" , password )
14861487
@@ -1504,7 +1505,7 @@ async def validate_hash(
15041505 Whether self.hash(password) == stored_hash.
15051506 """
15061507
1507- def _do_validate_hash (checked_hash : bytes ):
1508+ def _do_validate_hash (checked_hash : bytes ) -> bool :
15081509 # Normalise the Unicode in the password
15091510 pw = unicodedata .normalize ("NFKC" , password )
15101511
@@ -1581,7 +1582,7 @@ async def complete_sso_login(
15811582 client_redirect_url : str ,
15821583 extra_attributes : Optional [JsonDict ] = None ,
15831584 new_user : bool = False ,
1584- ):
1585+ ) -> None :
15851586 """Having figured out a mxid for this user, complete the HTTP request
15861587
15871588 Args:
@@ -1627,7 +1628,7 @@ def _complete_sso_login(
16271628 extra_attributes : Optional [JsonDict ] = None ,
16281629 new_user : bool = False ,
16291630 user_profile_data : Optional [ProfileInfo ] = None ,
1630- ):
1631+ ) -> None :
16311632 """
16321633 The synchronous portion of complete_sso_login.
16331634
@@ -1726,17 +1727,17 @@ def _expire_sso_extra_attributes(self) -> None:
17261727 del self ._extra_attributes [user_id ]
17271728
17281729 @staticmethod
1729- def add_query_param_to_url (url : str , param_name : str , param : Any ):
1730+ def add_query_param_to_url (url : str , param_name : str , param : Any ) -> str :
17301731 url_parts = list (urllib .parse .urlparse (url ))
17311732 query = urllib .parse .parse_qsl (url_parts [4 ], keep_blank_values = True )
17321733 query .append ((param_name , param ))
17331734 url_parts [4 ] = urllib .parse .urlencode (query )
17341735 return urllib .parse .urlunparse (url_parts )
17351736
17361737
1737- @attr .s (slots = True )
1738+ @attr .s (slots = True , auto_attribs = True )
17381739class MacaroonGenerator :
1739- hs = attr . ib ()
1740+ hs : "HomeServer"
17401741
17411742 def generate_guest_access_token (self , user_id : str ) -> str :
17421743 macaroon = self ._generate_base_macaroon (user_id )
@@ -1816,15 +1817,17 @@ class PasswordProvider:
18161817 """
18171818
18181819 @classmethod
1819- def load (cls , module , config , module_api : ModuleApi ) -> "PasswordProvider" :
1820+ def load (
1821+ cls , module : Type , config : JsonDict , module_api : ModuleApi
1822+ ) -> "PasswordProvider" :
18201823 try :
18211824 pp = module (config = config , account_handler = module_api )
18221825 except Exception as e :
18231826 logger .error ("Error while initializing %r: %s" , module , e )
18241827 raise
18251828 return cls (pp , module_api )
18261829
1827- def __init__ (self , pp , module_api : ModuleApi ):
1830+ def __init__ (self , pp : "PasswordProvider" , module_api : ModuleApi ):
18281831 self ._pp = pp
18291832 self ._module_api = module_api
18301833
@@ -1838,7 +1841,7 @@ def __init__(self, pp, module_api: ModuleApi):
18381841 if g :
18391842 self ._supported_login_types .update (g ())
18401843
1841- def __str__ (self ):
1844+ def __str__ (self ) -> str :
18421845 return str (self ._pp )
18431846
18441847 def get_supported_login_types (self ) -> Mapping [str , Iterable [str ]]:
@@ -1876,19 +1879,19 @@ async def check_auth(
18761879 """
18771880 # first grandfather in a call to check_password
18781881 if login_type == LoginType .PASSWORD :
1879- g = getattr (self ._pp , "check_password" , None )
1880- if g :
1882+ check_password = getattr (self ._pp , "check_password" , None )
1883+ if check_password :
18811884 qualified_user_id = self ._module_api .get_qualified_user_id (username )
1882- is_valid = await self . _pp . check_password (
1885+ is_valid = await check_password (
18831886 qualified_user_id , login_dict ["password" ]
18841887 )
18851888 if is_valid :
18861889 return qualified_user_id , None
18871890
1888- g = getattr (self ._pp , "check_auth" , None )
1889- if not g :
1891+ check_auth = getattr (self ._pp , "check_auth" , None )
1892+ if not check_auth :
18901893 return None
1891- result = await g (username , login_type , login_dict )
1894+ result = await check_auth (username , login_type , login_dict )
18921895
18931896 # Check if the return value is a str or a tuple
18941897 if isinstance (result , str ):
0 commit comments