From 0f29e9f71b14259c8cd6ddd9e09619ed593eba97 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sat, 31 Mar 2018 10:52:27 -0700 Subject: [PATCH] mypy: Improve type annotations in Zulip API. - Reduce use of Any, eg. in Callable parameters & narrow List; - Use Optional where appropriate in more locations. --- zulip/zulip/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index c070057..3a90aef 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -390,7 +390,7 @@ class Client(object): self.client_cert = client_cert self.client_cert_key = client_cert_key - self.session = None # type: Union[None, requests.Session] + self.session = None # type: Optional[requests.Session] self.has_connected = False @@ -443,7 +443,7 @@ class Client(object): ) def do_api_query(self, orig_request, url, method="POST", longpolling=False, files=None): - # type: (Mapping[str, Any], str, str, bool, List[IO[Any]]) -> Dict[str, Any] + # type: (Mapping[str, Any], str, str, bool, Optional[List[IO[Any]]]) -> Dict[str, Any] if files is None: files = [] @@ -577,7 +577,7 @@ class Client(object): "status_code": res.status_code} def call_endpoint(self, url=None, method="POST", request=None, longpolling=False, files=None): - # type: (str, str, Dict[str, Any], bool, List[IO[Any]]) -> Dict[str, Any] + # type: (Optional[str], str, Optional[Dict[str, Any]], bool, Optional[List[IO[Any]]]) -> Dict[str, Any] if request is None: request = dict() versioned_url = API_VERSTRING + (url if url is not None else "") @@ -585,7 +585,7 @@ class Client(object): longpolling=longpolling, files=files) def call_on_each_event(self, callback, event_types=None, narrow=None): - # type: (Callable[[Any], None], Optional[List[str]], Any) -> None + # type: (Callable[[Dict[str, Any]], None], Optional[List[str]], Optional[List[List[str]]]) -> None if narrow is None: narrow = [] @@ -645,9 +645,9 @@ class Client(object): callback(event) def call_on_each_message(self, callback): - # type: (Callable[[Any], None]) -> None + # type: (Callable[[Dict[str, Any]], None]) -> None def event_callback(event): - # type: (Dict[str, str]) -> None + # type: (Dict[str, Any]) -> None if event['type'] == 'message': callback(event['message']) self.call_on_each_event(event_callback, ['message']) @@ -696,7 +696,7 @@ class Client(object): ) def register(self, event_types=None, narrow=None, **kwargs): - # type: (Iterable[str], Any, **Any) -> Dict[str, Any] + # type: (Optional[Iterable[str]], Optional[List[List[str]]], **Any) -> Dict[str, Any] ''' Example usage: @@ -742,7 +742,7 @@ class Client(object): ) def get_profile(self, request=None): - # type: (Dict[str, Any]) -> Dict[str, Any] + # type: (Optional[Dict[str, Any]]) -> Dict[str, Any] ''' Example usage: @@ -780,7 +780,7 @@ class Client(object): ) def get_members(self, request=None): - # type: (Dict[str, Any]) -> Dict[str, Any] + # type: (Optional[Dict[str, Any]]) -> Dict[str, Any] ''' See examples/list-members for example usage. ''' @@ -791,7 +791,7 @@ class Client(object): ) def list_subscriptions(self, request=None): - # type: (Dict[str, Any]) -> Dict[str, Any] + # type: (Optional[Dict[str, Any]]) -> Dict[str, Any] ''' See examples/list-subscriptions for example usage. ''' @@ -865,7 +865,7 @@ class Client(object): ) def render_message(self, request=None): - # type: (Dict[str, Any]) -> Dict[str, Any] + # type: (Optional[Dict[str, Any]]) -> Dict[str, Any] ''' Example usage: @@ -879,7 +879,7 @@ class Client(object): ) def create_user(self, request=None): - # type: (Dict[str, Any]) -> Dict[str, Any] + # type: (Optional[Dict[str, Any]]) -> Dict[str, Any] ''' See examples/create-user for example usage. '''