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

Commit 744756d

Browse files
author
Sean Quah
committed
Add type hints to synapse.storage.databases.main.client_ips
1 parent cf20c86 commit 744756d

File tree

5 files changed

+122
-45
lines changed

5 files changed

+122
-45
lines changed

changelog.d/10972.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add type hints to `synapse.storage.databases.main.client_ips`.

mypy.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ files =
5353
synapse/storage/_base.py,
5454
synapse/storage/background_updates.py,
5555
synapse/storage/databases/main/appservice.py,
56+
synapse/storage/databases/main/client_ips.py,
5657
synapse/storage/databases/main/events.py,
5758
synapse/storage/databases/main/keys.py,
5859
synapse/storage/databases/main/pusher.py,
@@ -99,6 +100,9 @@ disallow_untyped_defs = True
99100
[mypy-synapse.rest.*]
100101
disallow_untyped_defs = True
101102

103+
[mypy-synapse.storage.databases.main.client_ips]
104+
disallow_untyped_defs = True
105+
102106
[mypy-synapse.util.batching_queue]
103107
disallow_untyped_defs = True
104108

synapse/handlers/device.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
import logging
17-
from typing import TYPE_CHECKING, Collection, Dict, Iterable, List, Optional, Set, Tuple
17+
from typing import (
18+
TYPE_CHECKING,
19+
Any,
20+
Collection,
21+
Dict,
22+
Iterable,
23+
List,
24+
Mapping,
25+
Optional,
26+
Set,
27+
Tuple,
28+
)
1829

1930
from synapse.api import errors
2031
from synapse.api.constants import EventTypes
@@ -595,7 +606,7 @@ async def rehydrate_device(
595606

596607

597608
def _update_device_from_client_ips(
598-
device: JsonDict, client_ips: Dict[Tuple[str, str], JsonDict]
609+
device: JsonDict, client_ips: Mapping[Tuple[str, str], Mapping[str, Any]]
599610
) -> None:
600611
ip = client_ips.get((device["user_id"], device["device_id"]), {})
601612
device.update({"last_seen_ts": ip.get("last_seen"), "last_seen_ip": ip.get("ip")})

synapse/module_api/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,9 @@ async def get_user_ip_and_agents(
773773
# Sanitize some of the data. We don't want to return tokens.
774774
return [
775775
UserIpAndAgent(
776-
ip=str(data["ip"]),
777-
user_agent=str(data["user_agent"]),
778-
last_seen=int(data["last_seen"]),
776+
ip=data["ip"],
777+
user_agent=data["user_agent"],
778+
last_seen=data["last_seen"],
779779
)
780780
for data in raw_data
781781
]

0 commit comments

Comments
 (0)