This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add type hints to various handlers. #9223
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8a72405
Add type hints to acme handlers.
clokep a4434a7
Add type hints to set_password handler.
clokep 02b5509
Add type hints to search handler.
clokep 3f2562b
Add type hints to state_deltas handler.
clokep 706060a
Add type hints to typing handler.
clokep 23b3a58
Add type hints to stats handler.
clokep 50927fc
Add type hints to group local handler.
clokep 3f34357
Newsfragment
clokep f67b6e6
Fix import of Collection.
clokep 7115c66
Import Counter from typing extensions.
clokep 47c7c16
Review comments.
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,9 @@ | |
# limitations under the License. | ||
|
||
import logging | ||
from collections import Counter | ||
from enum import Enum | ||
from itertools import chain | ||
from typing import Any, Dict, List, Optional, Tuple | ||
from typing import Any, Counter, Dict, List, Optional, Tuple | ||
|
||
from twisted.internet.defer import DeferredLock | ||
|
||
|
@@ -319,7 +318,9 @@ def _get_statistics_for_subject_txn( | |
return slice_list | ||
|
||
@cached() | ||
async def get_earliest_token_for_stats(self, stats_type: str, id: str) -> int: | ||
async def get_earliest_token_for_stats( | ||
self, stats_type: str, id: str | ||
) -> Optional[int]: | ||
""" | ||
Fetch the "earliest token". This is used by the room stats delta | ||
processor to ignore deltas that have been processed between the | ||
|
@@ -339,7 +340,7 @@ async def get_earliest_token_for_stats(self, stats_type: str, id: str) -> int: | |
) | ||
|
||
async def bulk_update_stats_delta( | ||
self, ts: int, updates: Dict[str, Dict[str, Dict[str, Counter]]], stream_id: int | ||
self, ts: int, updates: Dict[str, Dict[str, Counter[str]]], stream_id: int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just wrong, |
||
) -> None: | ||
"""Bulk update stats tables for a given stream_id and updates the stats | ||
incremental position. | ||
|
@@ -665,7 +666,7 @@ def _upsert_copy_from_table_with_additive_relatives_txn( | |
|
||
async def get_changes_room_total_events_and_bytes( | ||
self, min_pos: int, max_pos: int | ||
) -> Dict[str, Dict[str, int]]: | ||
) -> Tuple[Dict[str, Dict[str, int]], Dict[str, Dict[str, int]]]: | ||
"""Fetches the counts of events in the given range of stream IDs. | ||
|
||
Args: | ||
|
@@ -683,18 +684,19 @@ async def get_changes_room_total_events_and_bytes( | |
max_pos, | ||
) | ||
|
||
def get_changes_room_total_events_and_bytes_txn(self, txn, low_pos, high_pos): | ||
def get_changes_room_total_events_and_bytes_txn( | ||
self, txn, low_pos: int, high_pos: int | ||
) -> Tuple[Dict[str, Dict[str, int]], Dict[str, Dict[str, int]]]: | ||
"""Gets the total_events and total_event_bytes counts for rooms and | ||
senders, in a range of stream_orderings (including backfilled events). | ||
|
||
Args: | ||
txn | ||
low_pos (int): Low stream ordering | ||
high_pos (int): High stream ordering | ||
low_pos: Low stream ordering | ||
high_pos: High stream ordering | ||
|
||
Returns: | ||
tuple[dict[str, dict[str, int]], dict[str, dict[str, int]]]: The | ||
room and user deltas for total_events/total_event_bytes in the | ||
The room and user deltas for total_events/total_event_bytes in the | ||
format of `stats_id` -> fields | ||
""" | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine because
fields
is aDict[str, int]
, which in this case is effectively the same asCounter[str]
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much, the alternative would be to make
user_deltas
aDict[str, Dict[str, int]]
instead of aDict[str, Counter[str]]
I think? Would that be better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, it's fine, just wanted to check my understanding of the change was correct :)