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

Add type annotations to tests.storage.test_appservice. #11488

Merged
merged 9 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11488.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add type annotations to `tests.storage.test_appservice`.
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ exclude = (?x)
|tests/server_notices/test_resource_limits_server_notices.py
|tests/state/test_v2.py
|tests/storage/test_account_data.py
|tests/storage/test_appservice.py
|tests/storage/test_background_update.py
|tests/storage/test_base.py
|tests/storage/test_client_ips.py
Expand Down
3 changes: 2 additions & 1 deletion synapse/appservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
import logging
import re
from enum import Enum
from typing import TYPE_CHECKING, Iterable, List, Match, Optional

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


class ApplicationServiceState:
class ApplicationServiceState(Enum):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly question, but this change isn't visible to the module API right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a silly question! As far as I can tell, no it's not (and I can't think of any interfaces where it'd make sense). :)

DOWN = "down"
UP = "up"

Expand Down
6 changes: 3 additions & 3 deletions synapse/storage/databases/main/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def get_appservices_by_state(
A list of ApplicationServices, which may be empty.
"""
results = await self.db_pool.simple_select_list(
"application_services_state", {"state": state}, ["as_id"]
"application_services_state", {"state": state.value}, ["as_id"]
)
# NB: This assumes this class is linked with ApplicationServiceStore
as_list = self.get_app_services()
Expand Down Expand Up @@ -173,7 +173,7 @@ async def get_appservice_state(
desc="get_appservice_state",
)
if result:
return result.get("state")
return ApplicationServiceState(result.get("state"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small note to say that this changed the behaviour of the function. Previously this function returned None if state was null in the DB, but with this change the function errors instead.

This is fixed in #12680 (comment)

return None

async def set_appservice_state(
Expand All @@ -186,7 +186,7 @@ async def set_appservice_state(
state: The connectivity state to apply.
"""
await self.db_pool.simple_upsert(
"application_services_state", {"as_id": service.id}, {"state": state}
"application_services_state", {"as_id": service.id}, {"state": state.value}
)

async def create_appservice_txn(
Expand Down
Loading