Add missing type hints to `synapse.storage.database`. (#15230)
parent
e7c3832ba6
commit
3d060eae6c
|
@ -0,0 +1 @@
|
||||||
|
Improve type hints.
|
3
mypy.ini
3
mypy.ini
|
@ -48,9 +48,6 @@ warn_unused_ignores = False
|
||||||
[mypy-synapse.util.caches.treecache]
|
[mypy-synapse.util.caches.treecache]
|
||||||
disallow_untyped_defs = False
|
disallow_untyped_defs = False
|
||||||
|
|
||||||
[mypy-synapse.storage.database]
|
|
||||||
disallow_untyped_defs = False
|
|
||||||
|
|
||||||
[mypy-tests.util.caches.test_descriptors]
|
[mypy-tests.util.caches.test_descriptors]
|
||||||
disallow_untyped_defs = False
|
disallow_untyped_defs = False
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ from typing import (
|
||||||
Tuple,
|
Tuple,
|
||||||
Type,
|
Type,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
|
Union,
|
||||||
cast,
|
cast,
|
||||||
overload,
|
overload,
|
||||||
)
|
)
|
||||||
|
@ -100,6 +101,15 @@ UNIQUE_INDEX_BACKGROUND_UPDATES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class _PoolConnection(Connection):
|
||||||
|
"""
|
||||||
|
A Connection from twisted.enterprise.adbapi.Connection.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def reconnect(self) -> None:
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
def make_pool(
|
def make_pool(
|
||||||
reactor: IReactorCore,
|
reactor: IReactorCore,
|
||||||
db_config: DatabaseConnectionConfig,
|
db_config: DatabaseConnectionConfig,
|
||||||
|
@ -856,7 +866,8 @@ class DatabasePool:
|
||||||
try:
|
try:
|
||||||
with opentracing.start_active_span(f"db.{desc}"):
|
with opentracing.start_active_span(f"db.{desc}"):
|
||||||
result = await self.runWithConnection(
|
result = await self.runWithConnection(
|
||||||
self.new_transaction,
|
# mypy seems to have an issue with this, maybe a bug?
|
||||||
|
self.new_transaction, # type: ignore[arg-type]
|
||||||
desc,
|
desc,
|
||||||
after_callbacks,
|
after_callbacks,
|
||||||
async_after_callbacks,
|
async_after_callbacks,
|
||||||
|
@ -892,7 +903,7 @@ class DatabasePool:
|
||||||
|
|
||||||
async def runWithConnection(
|
async def runWithConnection(
|
||||||
self,
|
self,
|
||||||
func: Callable[..., R],
|
func: Callable[Concatenate[LoggingDatabaseConnection, P], R],
|
||||||
*args: Any,
|
*args: Any,
|
||||||
db_autocommit: bool = False,
|
db_autocommit: bool = False,
|
||||||
isolation_level: Optional[int] = None,
|
isolation_level: Optional[int] = None,
|
||||||
|
@ -926,7 +937,7 @@ class DatabasePool:
|
||||||
|
|
||||||
start_time = monotonic_time()
|
start_time = monotonic_time()
|
||||||
|
|
||||||
def inner_func(conn, *args, **kwargs):
|
def inner_func(conn: _PoolConnection, *args: P.args, **kwargs: P.kwargs) -> R:
|
||||||
# We shouldn't be in a transaction. If we are then something
|
# We shouldn't be in a transaction. If we are then something
|
||||||
# somewhere hasn't committed after doing work. (This is likely only
|
# somewhere hasn't committed after doing work. (This is likely only
|
||||||
# possible during startup, as `run*` will ensure changes are
|
# possible during startup, as `run*` will ensure changes are
|
||||||
|
@ -1019,7 +1030,7 @@ class DatabasePool:
|
||||||
decoder: Optional[Callable[[Cursor], R]],
|
decoder: Optional[Callable[[Cursor], R]],
|
||||||
query: str,
|
query: str,
|
||||||
*args: Any,
|
*args: Any,
|
||||||
) -> R:
|
) -> Union[List[Tuple[Any, ...]], R]:
|
||||||
"""Runs a single query for a result set.
|
"""Runs a single query for a result set.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -1032,7 +1043,7 @@ class DatabasePool:
|
||||||
The result of decoder(results)
|
The result of decoder(results)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def interaction(txn):
|
def interaction(txn: LoggingTransaction) -> Union[List[Tuple[Any, ...]], R]:
|
||||||
txn.execute(query, args)
|
txn.execute(query, args)
|
||||||
if decoder:
|
if decoder:
|
||||||
return decoder(txn)
|
return decoder(txn)
|
||||||
|
|
Loading…
Reference in New Issue