From 33ccc04a326f37c0b68d9e47559600e460554939 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Fri, 22 Dec 2017 09:51:14 -0800 Subject: [PATCH] mypy: Amend code & typing of integrations, to pass with strict-optional. --- zulip/integrations/codebase/zulip_codebase_mirror | 4 ++-- zulip/integrations/git/zulip_git_config.py | 4 ++-- zulip/integrations/google/get-google-credentials | 4 +++- zulip/integrations/openshift/zulip_openshift_config.py | 6 +++--- zulip/integrations/zephyr/sync-public-streams | 4 ++-- zulip/integrations/zephyr/zephyr_mirror_backend.py | 6 +++--- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/zulip/integrations/codebase/zulip_codebase_mirror b/zulip/integrations/codebase/zulip_codebase_mirror index c109f15..ed7ade2 100755 --- a/zulip/integrations/codebase/zulip_codebase_mirror +++ b/zulip/integrations/codebase/zulip_codebase_mirror @@ -286,10 +286,10 @@ def run_mirror(): try: sleepInterval = 1 while True: - events = make_api_call("activity")[::-1] + events = make_api_call("activity") if events is not None: sleepInterval = 1 - for event in events: + for event in events[::-1]: timestamp = event.get('event', {}).get('timestamp', '') event_date = dateutil.parser.parse(timestamp) if event_date > since: diff --git a/zulip/integrations/git/zulip_git_config.py b/zulip/integrations/git/zulip_git_config.py index 4f49297..6ba36b8 100644 --- a/zulip/integrations/git/zulip_git_config.py +++ b/zulip/integrations/git/zulip_git_config.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from typing import Dict, Text +from typing import Dict, Text, Optional # Change these values to configure authentication for the plugin ZULIP_USER = "git-bot@example.com" @@ -42,7 +42,7 @@ ZULIP_API_KEY = "0123456789abcdef0123456789abcdef" # * topic "master" # And similarly for branch "test-post-receive" (for use when testing). def commit_notice_destination(repo, branch, commit): - # type: (Text, Text, Text) -> Dict[Text, Text] + # type: (Text, Text, Text) -> Optional[Dict[Text, Text]] if branch in ["master", "test-post-receive"]: return dict(stream = "commits", subject = u"%s" % (branch,)) diff --git a/zulip/integrations/google/get-google-credentials b/zulip/integrations/google/get-google-credentials index e919388..8b70248 100644 --- a/zulip/integrations/google/get-google-credentials +++ b/zulip/integrations/google/get-google-credentials @@ -8,9 +8,11 @@ from oauth2client import client from oauth2client import tools from oauth2client.file import Storage +from typing import Optional + try: import argparse - flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() + flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() # type: Optional[argparse.Namespace] except ImportError: flags = None diff --git a/zulip/integrations/openshift/zulip_openshift_config.py b/zulip/integrations/openshift/zulip_openshift_config.py index 9f4296d..faebbf3 100755 --- a/zulip/integrations/openshift/zulip_openshift_config.py +++ b/zulip/integrations/openshift/zulip_openshift_config.py @@ -21,7 +21,7 @@ # THE SOFTWARE. # https://github.com/python/mypy/issues/1141 -from typing import Dict, Text +from typing import Dict, Text, Optional # Change these values to configure authentication for the plugin ZULIP_USER = 'openshift-bot@example.com' @@ -42,7 +42,7 @@ ZULIP_API_KEY = '0123456789abcdef0123456789abcdef' # * topic "master" # And similarly for branch "test-post-receive" (for use when testing). def deployment_notice_destination(branch): - # type: (str) -> Dict[str, Text] + # type: (str) -> Optional[Dict[str, Text]] if branch in ['master', 'test-post-receive']: return dict(stream = 'deployments', subject = u'%s' % (branch,)) @@ -69,7 +69,7 @@ def format_deployment_message( ## If properly installed, the Zulip API should be in your import ## path, but if not, set a custom path below -ZULIP_API_PATH = None # type: str +ZULIP_API_PATH = None # type: Optional[str] # Set this to your Zulip server's API URI ZULIP_SITE = 'https://zulip.example.com' diff --git a/zulip/integrations/zephyr/sync-public-streams b/zulip/integrations/zephyr/sync-public-streams index 26fad9b..1ead1c5 100755 --- a/zulip/integrations/zephyr/sync-public-streams +++ b/zulip/integrations/zephyr/sync-public-streams @@ -11,10 +11,10 @@ import unicodedata sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'api')) import zulip -from typing import Set +from typing import Set, Optional def fetch_public_streams(): - # type: () -> Set[bytes] + # type: () -> Optional[Set[bytes]] public_streams = set() try: diff --git a/zulip/integrations/zephyr/zephyr_mirror_backend.py b/zulip/integrations/zephyr/zephyr_mirror_backend.py index 77f495f..8abe066 100755 --- a/zulip/integrations/zephyr/zephyr_mirror_backend.py +++ b/zulip/integrations/zephyr/zephyr_mirror_backend.py @@ -21,7 +21,7 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. from __future__ import absolute_import -from typing import IO, Any, Dict, List, Text, Union, Set, Tuple +from typing import IO, Any, Dict, List, Text, Union, Set, Tuple, Optional from types import FrameType import sys @@ -309,7 +309,7 @@ def parse_zephyr_body(zephyr_data, notice_format): return (zsig, body) def parse_crypt_table(zephyr_class, instance): - # type: (Text, str) -> str + # type: (Text, str) -> Optional[str] try: crypt_table = open(os.path.join(os.environ["HOME"], ".crypt-table")) except IOError: @@ -604,7 +604,7 @@ def send_unauthed_zephyr(zwrite_args, content): return send_zephyr(zwrite_args + ["-d"], content) def zcrypt_encrypt_content(zephyr_class, instance, content): - # type: (str, str, str) -> str + # type: (str, str, str) -> Optional[str] keypath = parse_crypt_table(zephyr_class, instance) if keypath is None: return None