|
21 | 21 | LINUX = platform.system() == "Linux"
|
22 | 22 | WSL = 'microsoft' in platform.release().lower()
|
23 | 23 |
|
24 |
| -Message = Dict[str, Any] |
| 24 | +Message = TypedDict('Message', { |
| 25 | + 'id': int, |
| 26 | + 'sender_id': int, |
| 27 | + 'content': str, |
| 28 | + 'recipient_id': int, |
| 29 | + 'timestamp': int, |
| 30 | + 'client': str, |
| 31 | + 'subject': str, |
| 32 | + 'topic_links': List[str], |
| 33 | + 'is_me_message': bool, |
| 34 | + 'reactions': List[Dict[str, Any]], |
| 35 | + 'submessages': List[Dict[str, Any]], |
| 36 | + 'flags': List[str], |
| 37 | + 'sender_full_name': str, |
| 38 | + 'sender_short_name': str, |
| 39 | + 'sender_email': str, |
| 40 | + 'sender_realm_str': str, |
| 41 | + 'display_recipient': Any, |
| 42 | + 'type': str, |
| 43 | + 'stream_id': int, |
| 44 | + 'avatar_url': str, |
| 45 | + 'content_type': str, |
| 46 | + }, total=False) |
25 | 47 |
|
26 | 48 | Index = TypedDict('Index', {
|
27 | 49 | 'pointer': Dict[str, Union[int, Set[None]]], # narrow_str, message_id
|
|
53 | 75 | edited_messages=set(),
|
54 | 76 | topics=defaultdict(list),
|
55 | 77 | search=set(),
|
56 |
| - messages=defaultdict(dict), |
| 78 | + # mypy bug: https://github.com/python/mypy/issues/7217 |
| 79 | + messages=defaultdict(lambda: Message()), |
57 | 80 | )
|
58 | 81 |
|
59 | 82 |
|
@@ -99,7 +122,7 @@ def _set_count_in_model(new_count: int, changed_messages: List[Message],
|
99 | 122 | # self-pm has only one display_recipient
|
100 | 123 | # 1-1 pms have 2 display_recipient
|
101 | 124 | elif len(message['display_recipient']) <= 2:
|
102 |
| - key = message['sender_id'] |
| 125 | + key = message['sender_id'] # type: ignore |
103 | 126 | unreads = unread_counts['unread_pms'] # type: ignore
|
104 | 127 | else: # If it's a group pm
|
105 | 128 | key = frozenset( # type: ignore
|
|
0 commit comments