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

Commit 733531e

Browse files
authored
Add final type hint to synapse.server. (#15035)
1 parent 7081bb5 commit 733531e

File tree

7 files changed

+11
-12
lines changed

7 files changed

+11
-12
lines changed

changelog.d/15035.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve type hints.

mypy.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ warn_unused_ignores = False
5353
[mypy-synapse.util.caches.treecache]
5454
disallow_untyped_defs = False
5555

56-
[mypy-synapse.server]
57-
disallow_untyped_defs = False
58-
5956
[mypy-synapse.storage.database]
6057
disallow_untyped_defs = False
6158

synapse/handlers/room.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ async def _send_events_for_new_room(
10761076
state_map: MutableStateMap[str] = {}
10771077
# current_state_group of last event created. Used for computing event context of
10781078
# events to be batched
1079-
current_state_group = None
1079+
current_state_group: Optional[int] = None
10801080

10811081
def create_event_dict(etype: str, content: JsonDict, **kwargs: Any) -> JsonDict:
10821082
e = {"type": etype, "content": content}

synapse/server.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import abc
2222
import functools
2323
import logging
24-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, TypeVar, cast
24+
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, TypeVar, cast
2525

2626
from twisted.internet.interfaces import IOpenSSLContextFactory
2727
from twisted.internet.tcp import Port
@@ -144,10 +144,10 @@
144144
from synapse.handlers.saml import SamlHandler
145145

146146

147-
T = TypeVar("T", bound=Callable[..., Any])
147+
T = TypeVar("T")
148148

149149

150-
def cache_in_self(builder: T) -> T:
150+
def cache_in_self(builder: Callable[["HomeServer"], T]) -> Callable[["HomeServer"], T]:
151151
"""Wraps a function called e.g. `get_foo`, checking if `self.foo` exists and
152152
returning if so. If not, calls the given function and sets `self.foo` to it.
153153
@@ -166,7 +166,7 @@ def cache_in_self(builder: T) -> T:
166166
building = [False]
167167

168168
@functools.wraps(builder)
169-
def _get(self):
169+
def _get(self: "HomeServer") -> T:
170170
try:
171171
return getattr(self, depname)
172172
except AttributeError:
@@ -185,9 +185,7 @@ def _get(self):
185185

186186
return dep
187187

188-
# We cast here as we need to tell mypy that `_get` has the same signature as
189-
# `builder`.
190-
return cast(T, _get)
188+
return _get
191189

192190

193191
class HomeServer(metaclass=abc.ABCMeta):

synapse/storage/_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class SQLBaseStore(metaclass=ABCMeta):
3737
per data store (and not one per physical database).
3838
"""
3939

40+
db_pool: DatabasePool
41+
4042
def __init__(
4143
self,
4244
database: DatabasePool,

synapse/storage/database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ class DatabasePool:
499499
"""
500500

501501
_TXN_ID = 0
502+
engine: BaseDatabaseEngine
502503

503504
def __init__(
504505
self,

synapse/storage/databases/main/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ async def _get_prevs_before_rejected(self, event_ids: Iterable[str]) -> Set[str]
306306

307307
# The set of event_ids to return. This includes all soft-failed events
308308
# and their prev events.
309-
existing_prevs = set()
309+
existing_prevs: Set[str] = set()
310310

311311
def _get_prevs_before_rejected_txn(
312312
txn: LoggingTransaction, batch: Collection[str]

0 commit comments

Comments
 (0)