typing: Convert function type annotations to Python 3 style.

Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and two fixes for use-before-define
issues:

-    def set_zulip_client(self, zulipToJabberClient: ZulipToJabberBot) -> None:
+    def set_zulip_client(self, zulipToJabberClient: 'ZulipToJabberBot') -> None:

-def init_from_options(options: Any, client: Optional[str] = None) -> Client:
+def init_from_options(options: Any, client: Optional[str] = None) -> 'Client':

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-04-18 15:59:12 -07:00 committed by Tim Abbott
parent 7c5f73dce9
commit 5428c5f296
42 changed files with 311 additions and 577 deletions

View file

@ -7,8 +7,7 @@ from unittest.mock import patch
from typing import Any, Dict, List
@contextmanager
def mock_http_conversation(http_data):
# type: (Dict[str, Any]) -> Any
def mock_http_conversation(http_data: Dict[str, Any]) -> Any:
"""
Use this context manager to mock and verify a bot's HTTP
requests to the third-party API (and provide the correct
@ -18,8 +17,7 @@ def mock_http_conversation(http_data):
http_data should be fixtures data formatted like the data
in zulip_bots/zulip_bots/bots/giphy/fixtures/test_normal.json
"""
def get_response(http_response, http_headers, is_raw_response):
# type: (Dict[str, Any], Dict[str, Any], bool) -> Any
def get_response(http_response: Dict[str, Any], http_headers: Dict[str, Any], is_raw_response: bool) -> Any:
"""Creates a fake `requests` Response with a desired HTTP response and
response headers.
"""
@ -31,8 +29,7 @@ def mock_http_conversation(http_data):
mock_result.status_code = http_headers.get('status', 200)
return mock_result
def assert_called_with_fields(mock_result, http_request, fields, meta):
# type: (Any, Dict[str, Any], List[str], Dict[str, Any]) -> None
def assert_called_with_fields(mock_result: Any, http_request: Dict[str, Any], fields: List[str], meta: Dict[str, Any]) -> None:
"""Calls `assert_called_with` on a mock object using an HTTP request.
Uses `fields` to determine which keys to look for in HTTP request and
to test; if a key is in `fields`, e.g., 'headers', it will be used in
@ -101,10 +98,8 @@ def mock_http_conversation(http_data):
)
@contextmanager
def mock_request_exception():
# type: () -> Any
def assert_mock_called(mock_result):
# type: (Any) -> None
def mock_request_exception() -> Any:
def assert_mock_called(mock_result: Any) -> None:
assert mock_result.called
with patch('requests.get') as mock_get: