Skip to content

Commit 8bcdf4c

Browse files
andersktimabbott
authored andcommitted
python: Convert TypedDict declarations to Python 3.6 style.
A subset of the diff generated by pyupgrade --py36-plus --keep-percent-format. Signed-off-by: Anders Kaseorg <anders@zulip.com>
1 parent f5b33f9 commit 8bcdf4c

File tree

8 files changed

+61
-68
lines changed

8 files changed

+61
-68
lines changed

tools/fetch-contributor-data

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ parser.add_argument('--max-retries', type=int, default=10,
3636
help='Number of times to retry fetching data from Github')
3737
args = parser.parse_args()
3838

39-
ContributorsJSON = TypedDict('ContributorsJSON', {
40-
'date': str,
41-
'contrib': List[Dict[str, Union[str, int]]],
42-
})
39+
class ContributorsJSON(TypedDict):
40+
date: str
41+
contrib: List[Dict[str, Union[str, int]]]
4342

4443
logger = logging.getLogger('zulip.fetch_contributors_json')
4544

zerver/lib/actions.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -987,17 +987,16 @@ def render_incoming_message(message: Message,
987987
raise JsonableError(_('Unable to render message'))
988988
return rendered_content
989989

990-
RecipientInfoResult = TypedDict('RecipientInfoResult', {
991-
'active_user_ids': Set[int],
992-
'push_notify_user_ids': Set[int],
993-
'stream_email_user_ids': Set[int],
994-
'stream_push_user_ids': Set[int],
995-
'wildcard_mention_user_ids': Set[int],
996-
'um_eligible_user_ids': Set[int],
997-
'long_term_idle_user_ids': Set[int],
998-
'default_bot_user_ids': Set[int],
999-
'service_bot_tuples': List[Tuple[int, int]],
1000-
})
990+
class RecipientInfoResult(TypedDict):
991+
active_user_ids: Set[int]
992+
push_notify_user_ids: Set[int]
993+
stream_email_user_ids: Set[int]
994+
stream_push_user_ids: Set[int]
995+
wildcard_mention_user_ids: Set[int]
996+
um_eligible_user_ids: Set[int]
997+
long_term_idle_user_ids: Set[int]
998+
default_bot_user_ids: Set[int]
999+
service_bot_tuples: List[Tuple[int, int]]
10011000

10021001
def get_recipient_info(recipient: Recipient,
10031002
sender_id: int,
@@ -4185,10 +4184,9 @@ def do_update_message_flags(user_profile: UserProfile,
41854184
statsd.incr("flags.%s.%s" % (flag, operation), count)
41864185
return count
41874186

4188-
MessageUpdateUserInfoResult = TypedDict('MessageUpdateUserInfoResult', {
4189-
'message_user_ids': Set[int],
4190-
'mention_user_ids': Set[int],
4191-
})
4187+
class MessageUpdateUserInfoResult(TypedDict):
4188+
message_user_ids: Set[int]
4189+
mention_user_ids: Set[int]
41924190

41934191
def notify_topic_moved_streams(user_profile: UserProfile,
41944192
old_stream: Stream, old_topic: str,

zerver/lib/bugdown/__init__.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ def cache_wrapper() -> ReturnT:
7878
return val
7979
return cache_wrapper
8080

81-
FullNameInfo = TypedDict('FullNameInfo', {
82-
'id': int,
83-
'email': str,
84-
'full_name': str,
85-
})
81+
class FullNameInfo(TypedDict):
82+
id: int
83+
email: str
84+
full_name: str
8685

8786
DbData = Dict[str, Any]
8887

@@ -292,12 +291,11 @@ def walk_tree(root: Element,
292291

293292
return results
294293

295-
ElementFamily = NamedTuple('ElementFamily', [
296-
('grandparent', Optional[Element]),
297-
('parent', Element),
298-
('child', Element),
299-
('in_blockquote', bool),
300-
])
294+
class ElementFamily(NamedTuple):
295+
grandparent: Optional[Element]
296+
parent: Element
297+
child: Element
298+
in_blockquote: bool
301299

302300
T = TypeVar("T")
303301

@@ -1529,10 +1527,9 @@ class BugdownListPreprocessor(markdown.preprocessors.Preprocessor):
15291527

15301528
def run(self, lines: List[str]) -> List[str]:
15311529
""" Insert a newline between a paragraph and ulist if missing """
1532-
Fence = NamedTuple('Fence', [
1533-
('fence_str', str),
1534-
('is_code', bool),
1535-
])
1530+
class Fence(NamedTuple):
1531+
fence_str: str
1532+
is_code: bool
15361533

15371534
inserts = 0
15381535
in_code_fence: bool = False

zerver/lib/display_recipient.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
"is_mirror_dummy",
1515
]
1616

17-
TinyStreamResult = TypedDict('TinyStreamResult', {
18-
'id': int,
19-
'name': str,
20-
})
17+
class TinyStreamResult(TypedDict):
18+
id: int
19+
name: str
2120

2221
@cache_with_key(lambda *args: display_recipient_cache_key(args[0]),
2322
timeout=3600*24*7)

zerver/lib/message.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,20 @@
6060

6161
RealmAlertWord = Dict[int, List[str]]
6262

63-
RawUnreadMessagesResult = TypedDict('RawUnreadMessagesResult', {
64-
'pm_dict': Dict[int, Any],
65-
'stream_dict': Dict[int, Any],
66-
'huddle_dict': Dict[int, Any],
67-
'mentions': Set[int],
68-
'muted_stream_ids': List[int],
69-
'unmuted_stream_msgs': Set[int],
70-
})
71-
72-
UnreadMessagesResult = TypedDict('UnreadMessagesResult', {
73-
'pms': List[Dict[str, Any]],
74-
'streams': List[Dict[str, Any]],
75-
'huddles': List[Dict[str, Any]],
76-
'mentions': List[int],
77-
'count': int,
78-
})
63+
class RawUnreadMessagesResult(TypedDict):
64+
pm_dict: Dict[int, Any]
65+
stream_dict: Dict[int, Any]
66+
huddle_dict: Dict[int, Any]
67+
mentions: Set[int]
68+
muted_stream_ids: List[int]
69+
unmuted_stream_msgs: Set[int]
70+
71+
class UnreadMessagesResult(TypedDict):
72+
pms: List[Dict[str, Any]]
73+
streams: List[Dict[str, Any]]
74+
huddles: List[Dict[str, Any]]
75+
mentions: List[int]
76+
count: int
7977

8078
# We won't try to fetch more unread message IDs from the database than
8179
# this limit. The limit is super high, in large part because it means

zerver/lib/types.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
ProfileFieldData = Dict[str, Union[Dict[str, str], str]]
3030

31-
UserDisplayRecipient = TypedDict('UserDisplayRecipient', {'email': str, 'full_name': str, 'short_name': str,
32-
'id': int, 'is_mirror_dummy': bool})
31+
class UserDisplayRecipient(TypedDict):
32+
email: str
33+
full_name: str
34+
short_name: str
35+
id: int
36+
is_mirror_dummy: bool
3337
DisplayRecipientT = Union[str, List[UserDisplayRecipient]]

zerver/tornado/event_queue.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,10 @@ def maybe_enqueue_notifications(user_profile_id: int, message_id: int, private_m
769769

770770
return notified
771771

772-
ClientInfo = TypedDict('ClientInfo', {
773-
'client': ClientDescriptor,
774-
'flags': Optional[Iterable[str]],
775-
'is_sender': bool,
776-
})
772+
class ClientInfo(TypedDict):
773+
client: ClientDescriptor
774+
flags: Optional[Iterable[str]]
775+
is_sender: bool
777776

778777
def get_client_info_for_message_event(event_template: Mapping[str, Any],
779778
users: Iterable[Mapping[str, Any]]) -> Dict[str, ClientInfo]:

zproject/backends.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,12 @@ def authenticate(self, request: Optional[HttpRequest]=None, *,
872872
return None
873873
return common_get_active_user(dev_auth_username, realm, return_data=return_data)
874874

875-
ExternalAuthMethodDictT = TypedDict('ExternalAuthMethodDictT', {
876-
'name': str,
877-
'display_name': str,
878-
'display_icon': Optional[str],
879-
'login_url': str,
880-
'signup_url': str,
881-
})
875+
class ExternalAuthMethodDictT(TypedDict):
876+
name: str
877+
display_name: str
878+
display_icon: Optional[str]
879+
login_url: str
880+
signup_url: str
882881

883882
class ExternalAuthMethod(ABC):
884883
"""

0 commit comments

Comments
 (0)