diff --git a/mypy.ini b/mypy.ini index 9a79176..d980ad0 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2,6 +2,7 @@ check_untyped_defs = True disallow_any_generics = True strict_optional = True +no_implicit_optional = True incremental = True scripts_are_modules = True diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 7efc14a..d7c5032 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -286,7 +286,7 @@ class Client(object): site=None, client=None, cert_bundle=None, insecure=None, client_cert=None, client_cert_key=None): - # type: (Optional[str], Optional[str], Optional[str], bool, bool, Optional[str], Optional[str], Optional[str], bool, Optional[str], Optional[str]) -> None + # type: (Optional[str], Optional[str], Optional[str], bool, bool, Optional[str], Optional[str], Optional[str], Optional[bool], Optional[str], Optional[str]) -> None if client is None: client = _default_client() diff --git a/zulip_bots/zulip_bots/bots/idonethis/idonethis.py b/zulip_bots/zulip_bots/bots/idonethis/idonethis.py index be289bc..88af20e 100644 --- a/zulip_bots/zulip_bots/bots/idonethis/idonethis.py +++ b/zulip_bots/zulip_bots/bots/idonethis/idonethis.py @@ -3,7 +3,7 @@ import requests import logging import re -from typing import Any, Dict +from typing import Any, Dict, Optional API_BASE_URL = "https://beta.idonethis.com/api/v2" @@ -25,7 +25,7 @@ class UnknownCommandSyntax(Exception): class UnspecifiedProblemException(Exception): pass -def make_API_request(endpoint: str, method: str="GET", body: Dict[str, str]=None) -> Any: +def make_API_request(endpoint: str, method: str="GET", body: Optional[Dict[str, str]]=None) -> Any: headers = {'Authorization': 'Token ' + api_key} if method == "GET": r = requests.get(API_BASE_URL + endpoint, headers=headers) @@ -52,7 +52,7 @@ def api_show_team(hash_id: str) -> Any: def api_show_users(hash_id: str) -> Any: return make_API_request("/teams/{}/members".format(hash_id)) -def api_list_entries(team_id: str=None) -> Any: +def api_list_entries(team_id: Optional[str]=None) -> Any: if team_id: return make_API_request("/entries?team_id={}".format(team_id)) else: diff --git a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py index e12616e..bf44d20 100644 --- a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py +++ b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py @@ -3,7 +3,7 @@ import random import logging import requests -from typing import Any, Dict +from typing import Any, Dict, Optional XKCD_TEMPLATE_URL = 'https://xkcd.com/%s/info.0.json' LATEST_XKCD_URL = 'https://xkcd.com/info.0.json' @@ -84,7 +84,7 @@ def get_xkcd_bot_response(message: Dict[str, str]) -> str: fetched['alt'], fetched['img'])) -def fetch_xkcd_query(mode: int, comic_id: str = None) -> Dict[str, str]: +def fetch_xkcd_query(mode: int, comic_id: Optional[str]=None) -> Dict[str, str]: try: if mode == XkcdBotCommand.LATEST: # Fetch the latest comic strip. url = LATEST_XKCD_URL diff --git a/zulip_bots/zulip_bots/bots/yoda/test_yoda.py b/zulip_bots/zulip_bots/bots/yoda/test_yoda.py index fee9931..9596f14 100644 --- a/zulip_bots/zulip_bots/bots/yoda/test_yoda.py +++ b/zulip_bots/zulip_bots/bots/yoda/test_yoda.py @@ -1,6 +1,8 @@ from zulip_bots.bots.yoda.yoda import ServiceUnavailableError from zulip_bots.test_lib import BotTestCase +from typing import Optional + class TestYodaBot(BotTestCase): bot_name = "yoda" @@ -18,7 +20,7 @@ class TestYodaBot(BotTestCase): @mention-bot You will learn how to speak like me someday. ''' - def _test(self, message: str, response: str, fixture: str=None) -> None: + def _test(self, message: str, response: str, fixture: Optional[str]=None) -> None: with self.mock_config_info({'api_key': '12345678'}): if fixture is not None: with self.mock_http_conversation(fixture):