From 6cd09e7396f97f4c1190a37559345511d44a3c40 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Fri, 22 Dec 2017 10:51:24 -0800 Subject: [PATCH] mypy: Amend youtube bot, to pass with strict-optional. Including switch to Optional from Union[None, T] for consistency. --- zulip_bots/zulip_bots/bots/youtube/youtube.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/youtube/youtube.py b/zulip_bots/zulip_bots/bots/youtube/youtube.py index 200ca7a..2aa9aef 100644 --- a/zulip_bots/zulip_bots/bots/youtube/youtube.py +++ b/zulip_bots/zulip_bots/bots/youtube/youtube.py @@ -3,7 +3,7 @@ import logging import sys from requests.exceptions import HTTPError, ConnectionError -from typing import Dict, Any, Union, List, Tuple +from typing import Dict, Any, Union, List, Tuple, Optional commands_list = ('list', 'top', 'help') @@ -81,7 +81,7 @@ def search_youtube(query: str, key: str, return videos -def get_command_query(message: Dict[str, str]) -> Tuple[Union[None, str], str]: +def get_command_query(message: Dict[str, str]) -> Tuple[Optional[str], str]: blocks = message['content'].lower().split() command = blocks[0] if command in commands_list: @@ -91,12 +91,11 @@ def get_command_query(message: Dict[str, str]) -> Tuple[Union[None, str], str]: return None, message['content'] -def get_bot_response(query: Union[str, None], command: Union[str, None], config_info: Dict[str, str]) -> str: +def get_bot_response(query: Optional[str], command: Optional[str], config_info: Dict[str, str]) -> str: key = config_info['key'] max_results = int(config_info['number_of_results']) region = config_info['video_region'] - reply = 'Here is what I found for `' + query + '` : ' video_list = [] # type: List[List[str]] try: if query == '' or query is None: @@ -114,6 +113,8 @@ def get_bot_response(query: Union[str, None], command: Union[str, None], config_ return 'Uh-Oh, couldn\'t process the request ' \ 'right now.\nPlease again later' + reply = 'Here is what I found for `' + query + '` : ' + if len(video_list) == 0: return 'Oops ! Sorry I couldn\'t find any video for `' + query + '` :slightly_frowning_face:' elif len(video_list) == 1: