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

Commit 3d060ea

Browse files
authored
Add missing type hints to synapse.storage.database. (#15230)
1 parent e7c3832 commit 3d060ea

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

changelog.d/15230.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
@@ -48,9 +48,6 @@ warn_unused_ignores = False
4848
[mypy-synapse.util.caches.treecache]
4949
disallow_untyped_defs = False
5050

51-
[mypy-synapse.storage.database]
52-
disallow_untyped_defs = False
53-
5451
[mypy-tests.util.caches.test_descriptors]
5552
disallow_untyped_defs = False
5653

synapse/storage/database.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
Tuple,
3535
Type,
3636
TypeVar,
37+
Union,
3738
cast,
3839
overload,
3940
)
@@ -100,6 +101,15 @@
100101
}
101102

102103

104+
class _PoolConnection(Connection):
105+
"""
106+
A Connection from twisted.enterprise.adbapi.Connection.
107+
"""
108+
109+
def reconnect(self) -> None:
110+
...
111+
112+
103113
def make_pool(
104114
reactor: IReactorCore,
105115
db_config: DatabaseConnectionConfig,
@@ -856,7 +866,8 @@ async def _runInteraction() -> R:
856866
try:
857867
with opentracing.start_active_span(f"db.{desc}"):
858868
result = await self.runWithConnection(
859-
self.new_transaction,
869+
# mypy seems to have an issue with this, maybe a bug?
870+
self.new_transaction, # type: ignore[arg-type]
860871
desc,
861872
after_callbacks,
862873
async_after_callbacks,
@@ -892,7 +903,7 @@ async def _runInteraction() -> R:
892903

893904
async def runWithConnection(
894905
self,
895-
func: Callable[..., R],
906+
func: Callable[Concatenate[LoggingDatabaseConnection, P], R],
896907
*args: Any,
897908
db_autocommit: bool = False,
898909
isolation_level: Optional[int] = None,
@@ -926,7 +937,7 @@ async def runWithConnection(
926937

927938
start_time = monotonic_time()
928939

929-
def inner_func(conn, *args, **kwargs):
940+
def inner_func(conn: _PoolConnection, *args: P.args, **kwargs: P.kwargs) -> R:
930941
# We shouldn't be in a transaction. If we are then something
931942
# somewhere hasn't committed after doing work. (This is likely only
932943
# possible during startup, as `run*` will ensure changes are
@@ -1019,7 +1030,7 @@ async def execute(
10191030
decoder: Optional[Callable[[Cursor], R]],
10201031
query: str,
10211032
*args: Any,
1022-
) -> R:
1033+
) -> Union[List[Tuple[Any, ...]], R]:
10231034
"""Runs a single query for a result set.
10241035
10251036
Args:
@@ -1032,7 +1043,7 @@ async def execute(
10321043
The result of decoder(results)
10331044
"""
10341045

1035-
def interaction(txn):
1046+
def interaction(txn: LoggingTransaction) -> Union[List[Tuple[Any, ...]], R]:
10361047
txn.execute(query, args)
10371048
if decoder:
10381049
return decoder(txn)

0 commit comments

Comments
 (0)