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

Commit 435f044

Browse files
authored
Add type annotations to tests.storage.test_appservice. (#11488)
1 parent f61462e commit 435f044

File tree

5 files changed

+98
-53
lines changed

5 files changed

+98
-53
lines changed

changelog.d/11488.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add type annotations to `tests.storage.test_appservice`.

mypy.ini

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ exclude = (?x)
111111
|tests/server_notices/test_resource_limits_server_notices.py
112112
|tests/state/test_v2.py
113113
|tests/storage/test_account_data.py
114-
|tests/storage/test_appservice.py
115114
|tests/storage/test_background_update.py
116115
|tests/storage/test_base.py
117116
|tests/storage/test_client_ips.py

synapse/appservice/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
import logging
1515
import re
16+
from enum import Enum
1617
from typing import TYPE_CHECKING, Iterable, List, Match, Optional
1718

1819
from synapse.api.constants import EventTypes
@@ -27,7 +28,7 @@
2728
logger = logging.getLogger(__name__)
2829

2930

30-
class ApplicationServiceState:
31+
class ApplicationServiceState(Enum):
3132
DOWN = "down"
3233
UP = "up"
3334

synapse/storage/databases/main/appservice.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def get_appservices_by_state(
143143
A list of ApplicationServices, which may be empty.
144144
"""
145145
results = await self.db_pool.simple_select_list(
146-
"application_services_state", {"state": state}, ["as_id"]
146+
"application_services_state", {"state": state.value}, ["as_id"]
147147
)
148148
# NB: This assumes this class is linked with ApplicationServiceStore
149149
as_list = self.get_app_services()
@@ -173,7 +173,7 @@ async def get_appservice_state(
173173
desc="get_appservice_state",
174174
)
175175
if result:
176-
return result.get("state")
176+
return ApplicationServiceState(result.get("state"))
177177
return None
178178

179179
async def set_appservice_state(
@@ -186,7 +186,7 @@ async def set_appservice_state(
186186
state: The connectivity state to apply.
187187
"""
188188
await self.db_pool.simple_upsert(
189-
"application_services_state", {"as_id": service.id}, {"state": state}
189+
"application_services_state", {"as_id": service.id}, {"state": state.value}
190190
)
191191

192192
async def create_appservice_txn(

0 commit comments

Comments
 (0)