mirror of
https://github.com/matrix-org/synapse.git
synced 2025-01-15 04:37:12 +00:00
Add final type hint to synapse.server. (#15035)
This commit is contained in:
parent
7081bb56e2
commit
733531ee3e
1
changelog.d/15035.misc
Normal file
1
changelog.d/15035.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Improve type hints.
|
3
mypy.ini
3
mypy.ini
@ -53,9 +53,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.server]
|
|
||||||
disallow_untyped_defs = False
|
|
||||||
|
|
||||||
[mypy-synapse.storage.database]
|
[mypy-synapse.storage.database]
|
||||||
disallow_untyped_defs = False
|
disallow_untyped_defs = False
|
||||||
|
|
||||||
|
@ -1076,7 +1076,7 @@ class RoomCreationHandler:
|
|||||||
state_map: MutableStateMap[str] = {}
|
state_map: MutableStateMap[str] = {}
|
||||||
# current_state_group of last event created. Used for computing event context of
|
# current_state_group of last event created. Used for computing event context of
|
||||||
# events to be batched
|
# events to be batched
|
||||||
current_state_group = None
|
current_state_group: Optional[int] = None
|
||||||
|
|
||||||
def create_event_dict(etype: str, content: JsonDict, **kwargs: Any) -> JsonDict:
|
def create_event_dict(etype: str, content: JsonDict, **kwargs: Any) -> JsonDict:
|
||||||
e = {"type": etype, "content": content}
|
e = {"type": etype, "content": content}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
import abc
|
import abc
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, TypeVar, cast
|
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, TypeVar, cast
|
||||||
|
|
||||||
from twisted.internet.interfaces import IOpenSSLContextFactory
|
from twisted.internet.interfaces import IOpenSSLContextFactory
|
||||||
from twisted.internet.tcp import Port
|
from twisted.internet.tcp import Port
|
||||||
@ -144,10 +144,10 @@ if TYPE_CHECKING:
|
|||||||
from synapse.handlers.saml import SamlHandler
|
from synapse.handlers.saml import SamlHandler
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T", bound=Callable[..., Any])
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
def cache_in_self(builder: T) -> T:
|
def cache_in_self(builder: Callable[["HomeServer"], T]) -> Callable[["HomeServer"], T]:
|
||||||
"""Wraps a function called e.g. `get_foo`, checking if `self.foo` exists and
|
"""Wraps a function called e.g. `get_foo`, checking if `self.foo` exists and
|
||||||
returning if so. If not, calls the given function and sets `self.foo` to it.
|
returning if so. If not, calls the given function and sets `self.foo` to it.
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ def cache_in_self(builder: T) -> T:
|
|||||||
building = [False]
|
building = [False]
|
||||||
|
|
||||||
@functools.wraps(builder)
|
@functools.wraps(builder)
|
||||||
def _get(self):
|
def _get(self: "HomeServer") -> T:
|
||||||
try:
|
try:
|
||||||
return getattr(self, depname)
|
return getattr(self, depname)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -185,9 +185,7 @@ def cache_in_self(builder: T) -> T:
|
|||||||
|
|
||||||
return dep
|
return dep
|
||||||
|
|
||||||
# We cast here as we need to tell mypy that `_get` has the same signature as
|
return _get
|
||||||
# `builder`.
|
|
||||||
return cast(T, _get)
|
|
||||||
|
|
||||||
|
|
||||||
class HomeServer(metaclass=abc.ABCMeta):
|
class HomeServer(metaclass=abc.ABCMeta):
|
||||||
|
@ -37,6 +37,8 @@ class SQLBaseStore(metaclass=ABCMeta):
|
|||||||
per data store (and not one per physical database).
|
per data store (and not one per physical database).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
db_pool: DatabasePool
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
database: DatabasePool,
|
database: DatabasePool,
|
||||||
|
@ -499,6 +499,7 @@ class DatabasePool:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
_TXN_ID = 0
|
_TXN_ID = 0
|
||||||
|
engine: BaseDatabaseEngine
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -306,7 +306,7 @@ class PersistEventsStore:
|
|||||||
|
|
||||||
# The set of event_ids to return. This includes all soft-failed events
|
# The set of event_ids to return. This includes all soft-failed events
|
||||||
# and their prev events.
|
# and their prev events.
|
||||||
existing_prevs = set()
|
existing_prevs: Set[str] = set()
|
||||||
|
|
||||||
def _get_prevs_before_rejected_txn(
|
def _get_prevs_before_rejected_txn(
|
||||||
txn: LoggingTransaction, batch: Collection[str]
|
txn: LoggingTransaction, batch: Collection[str]
|
||||||
|
Loading…
Reference in New Issue
Block a user