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>
This commit is contained in:
Anders Kaseorg 2020-05-01 21:24:43 -07:00 committed by Tim Abbott
parent f5b33f9398
commit 8bcdf4ca97
8 changed files with 60 additions and 67 deletions

View File

@ -36,10 +36,9 @@ parser.add_argument('--max-retries', type=int, default=10,
help='Number of times to retry fetching data from Github')
args = parser.parse_args()
ContributorsJSON = TypedDict('ContributorsJSON', {
'date': str,
'contrib': List[Dict[str, Union[str, int]]],
})
class ContributorsJSON(TypedDict):
date: str
contrib: List[Dict[str, Union[str, int]]]
logger = logging.getLogger('zulip.fetch_contributors_json')

View File

@ -987,17 +987,16 @@ def render_incoming_message(message: Message,
raise JsonableError(_('Unable to render message'))
return rendered_content
RecipientInfoResult = TypedDict('RecipientInfoResult', {
'active_user_ids': Set[int],
'push_notify_user_ids': Set[int],
'stream_email_user_ids': Set[int],
'stream_push_user_ids': Set[int],
'wildcard_mention_user_ids': Set[int],
'um_eligible_user_ids': Set[int],
'long_term_idle_user_ids': Set[int],
'default_bot_user_ids': Set[int],
'service_bot_tuples': List[Tuple[int, int]],
})
class RecipientInfoResult(TypedDict):
active_user_ids: Set[int]
push_notify_user_ids: Set[int]
stream_email_user_ids: Set[int]
stream_push_user_ids: Set[int]
wildcard_mention_user_ids: Set[int]
um_eligible_user_ids: Set[int]
long_term_idle_user_ids: Set[int]
default_bot_user_ids: Set[int]
service_bot_tuples: List[Tuple[int, int]]
def get_recipient_info(recipient: Recipient,
sender_id: int,
@ -4185,10 +4184,9 @@ def do_update_message_flags(user_profile: UserProfile,
statsd.incr("flags.%s.%s" % (flag, operation), count)
return count
MessageUpdateUserInfoResult = TypedDict('MessageUpdateUserInfoResult', {
'message_user_ids': Set[int],
'mention_user_ids': Set[int],
})
class MessageUpdateUserInfoResult(TypedDict):
message_user_ids: Set[int]
mention_user_ids: Set[int]
def notify_topic_moved_streams(user_profile: UserProfile,
old_stream: Stream, old_topic: str,

View File

@ -78,11 +78,10 @@ def one_time(method: Callable[[], ReturnT]) -> Callable[[], ReturnT]:
return val
return cache_wrapper
FullNameInfo = TypedDict('FullNameInfo', {
'id': int,
'email': str,
'full_name': str,
})
class FullNameInfo(TypedDict):
id: int
email: str
full_name: str
DbData = Dict[str, Any]
@ -292,12 +291,11 @@ def walk_tree(root: Element,
return results
ElementFamily = NamedTuple('ElementFamily', [
('grandparent', Optional[Element]),
('parent', Element),
('child', Element),
('in_blockquote', bool),
])
class ElementFamily(NamedTuple):
grandparent: Optional[Element]
parent: Element
child: Element
in_blockquote: bool
T = TypeVar("T")
@ -1529,10 +1527,9 @@ class BugdownListPreprocessor(markdown.preprocessors.Preprocessor):
def run(self, lines: List[str]) -> List[str]:
""" Insert a newline between a paragraph and ulist if missing """
Fence = NamedTuple('Fence', [
('fence_str', str),
('is_code', bool),
])
class Fence(NamedTuple):
fence_str: str
is_code: bool
inserts = 0
in_code_fence: bool = False

View File

@ -14,10 +14,9 @@ display_recipient_fields = [
"is_mirror_dummy",
]
TinyStreamResult = TypedDict('TinyStreamResult', {
'id': int,
'name': str,
})
class TinyStreamResult(TypedDict):
id: int
name: str
@cache_with_key(lambda *args: display_recipient_cache_key(args[0]),
timeout=3600*24*7)

View File

@ -60,22 +60,20 @@ from typing_extensions import TypedDict
RealmAlertWord = Dict[int, List[str]]
RawUnreadMessagesResult = TypedDict('RawUnreadMessagesResult', {
'pm_dict': Dict[int, Any],
'stream_dict': Dict[int, Any],
'huddle_dict': Dict[int, Any],
'mentions': Set[int],
'muted_stream_ids': List[int],
'unmuted_stream_msgs': Set[int],
})
class RawUnreadMessagesResult(TypedDict):
pm_dict: Dict[int, Any]
stream_dict: Dict[int, Any]
huddle_dict: Dict[int, Any]
mentions: Set[int]
muted_stream_ids: List[int]
unmuted_stream_msgs: Set[int]
UnreadMessagesResult = TypedDict('UnreadMessagesResult', {
'pms': List[Dict[str, Any]],
'streams': List[Dict[str, Any]],
'huddles': List[Dict[str, Any]],
'mentions': List[int],
'count': int,
})
class UnreadMessagesResult(TypedDict):
pms: List[Dict[str, Any]]
streams: List[Dict[str, Any]]
huddles: List[Dict[str, Any]]
mentions: List[int]
count: int
# We won't try to fetch more unread message IDs from the database than
# this limit. The limit is super high, in large part because it means

View File

@ -28,6 +28,10 @@ UserFieldElement = Tuple[int, str, RealmUserValidator, Callable[[Any], Any], str
ProfileFieldData = Dict[str, Union[Dict[str, str], str]]
UserDisplayRecipient = TypedDict('UserDisplayRecipient', {'email': str, 'full_name': str, 'short_name': str,
'id': int, 'is_mirror_dummy': bool})
class UserDisplayRecipient(TypedDict):
email: str
full_name: str
short_name: str
id: int
is_mirror_dummy: bool
DisplayRecipientT = Union[str, List[UserDisplayRecipient]]

View File

@ -769,11 +769,10 @@ def maybe_enqueue_notifications(user_profile_id: int, message_id: int, private_m
return notified
ClientInfo = TypedDict('ClientInfo', {
'client': ClientDescriptor,
'flags': Optional[Iterable[str]],
'is_sender': bool,
})
class ClientInfo(TypedDict):
client: ClientDescriptor
flags: Optional[Iterable[str]]
is_sender: bool
def get_client_info_for_message_event(event_template: Mapping[str, Any],
users: Iterable[Mapping[str, Any]]) -> Dict[str, ClientInfo]:

View File

@ -872,13 +872,12 @@ class DevAuthBackend(ZulipAuthMixin):
return None
return common_get_active_user(dev_auth_username, realm, return_data=return_data)
ExternalAuthMethodDictT = TypedDict('ExternalAuthMethodDictT', {
'name': str,
'display_name': str,
'display_icon': Optional[str],
'login_url': str,
'signup_url': str,
})
class ExternalAuthMethodDictT(TypedDict):
name: str
display_name: str
display_icon: Optional[str]
login_url: str
signup_url: str
class ExternalAuthMethod(ABC):
"""