mypy: Add --disallow-any=generics & extend typing accordingly.
Also reset typing of ExternalBotHandler to Any after discussion.
This commit is contained in:
parent
424a4bb631
commit
28687f18ca
10 changed files with 54 additions and 51 deletions
|
@ -2,8 +2,7 @@ import chess
|
|||
import chess.uci
|
||||
import re
|
||||
import copy
|
||||
from typing import Any, Optional
|
||||
from zulip_bots.lib import ExternalBotHandler
|
||||
from typing import Any, Optional, Dict
|
||||
|
||||
START_REGEX = re.compile('start with other user$')
|
||||
START_COMPUTER_REGEX = re.compile(
|
||||
|
@ -23,7 +22,7 @@ class ChessHandler(object):
|
|||
'Stockfish program on this computer.'
|
||||
)
|
||||
|
||||
def initialize(self, bot_handler: ExternalBotHandler) -> None:
|
||||
def initialize(self, bot_handler: Any) -> None:
|
||||
self.config_info = bot_handler.get_config_info('chess')
|
||||
|
||||
try:
|
||||
|
@ -38,8 +37,8 @@ class ChessHandler(object):
|
|||
|
||||
def handle_message(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any
|
||||
) -> None:
|
||||
content = message['content']
|
||||
|
||||
|
@ -94,7 +93,7 @@ class ChessHandler(object):
|
|||
last_fen
|
||||
)
|
||||
|
||||
def start(self, message: dict, bot_handler: ExternalBotHandler) -> None:
|
||||
def start(self, message: Dict[str, str], bot_handler: Any) -> None:
|
||||
"""Starts a game with another user, with the current user as white.
|
||||
Replies to the bot handler.
|
||||
|
||||
|
@ -115,8 +114,8 @@ class ChessHandler(object):
|
|||
|
||||
def start_computer(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler,
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any,
|
||||
is_white_user: bool
|
||||
) -> None:
|
||||
"""Starts a game with the computer. Replies to the bot handler.
|
||||
|
@ -151,8 +150,8 @@ class ChessHandler(object):
|
|||
|
||||
def validate_board(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler,
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any,
|
||||
fen: str
|
||||
) -> Optional[chess.Board]:
|
||||
"""Validates a board based on its FEN string. Replies to the bot
|
||||
|
@ -179,8 +178,8 @@ class ChessHandler(object):
|
|||
|
||||
def validate_move(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler,
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any,
|
||||
last_board: chess.Board,
|
||||
move_san: str,
|
||||
is_computer: object
|
||||
|
@ -223,8 +222,8 @@ class ChessHandler(object):
|
|||
|
||||
def check_game_over(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler,
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any,
|
||||
new_board: chess.Board
|
||||
) -> bool:
|
||||
"""Checks if a game is over due to
|
||||
|
@ -280,8 +279,8 @@ class ChessHandler(object):
|
|||
|
||||
def move(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler,
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any,
|
||||
last_fen: str,
|
||||
move_san: str
|
||||
) -> None:
|
||||
|
@ -325,8 +324,8 @@ class ChessHandler(object):
|
|||
|
||||
def move_computer(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler,
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any,
|
||||
last_fen: str,
|
||||
move_san: str
|
||||
) -> None:
|
||||
|
@ -396,8 +395,8 @@ class ChessHandler(object):
|
|||
|
||||
def move_computer_first(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler,
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any,
|
||||
last_fen: str
|
||||
) -> None:
|
||||
"""Preforms a move for the computer without having the user go first in
|
||||
|
@ -447,8 +446,8 @@ class ChessHandler(object):
|
|||
|
||||
def resign(
|
||||
self,
|
||||
message: dict,
|
||||
bot_handler: ExternalBotHandler,
|
||||
message: Dict[str, str],
|
||||
bot_handler: Any,
|
||||
last_fen: str
|
||||
) -> None:
|
||||
"""Resigns the game for the current player.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# See readme.md for instructions on running this code.
|
||||
|
||||
from zulip_bots.lib import ExternalBotHandler
|
||||
from typing import Dict, Any
|
||||
|
||||
class IncrementorHandler(object):
|
||||
META = {
|
||||
|
@ -16,13 +16,13 @@ class IncrementorHandler(object):
|
|||
is @-mentioned, this number will be incremented in the same message.
|
||||
'''
|
||||
|
||||
def initialize(self, bot_handler: ExternalBotHandler) -> None:
|
||||
def initialize(self, bot_handler: Any) -> None:
|
||||
storage = bot_handler.storage
|
||||
if not storage.contains('number') or not storage.contains('message_id'):
|
||||
storage.put('number', 0)
|
||||
storage.put('message_id', None)
|
||||
|
||||
def handle_message(self, message: dict, bot_handler: ExternalBotHandler) -> None:
|
||||
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
|
||||
storage = bot_handler.storage
|
||||
num = storage.get('number')
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@ import requests
|
|||
import logging
|
||||
import re
|
||||
from six.moves import urllib
|
||||
from zulip_bots.lib import ExternalBotHandler
|
||||
from typing import Optional
|
||||
from zulip_bots.lib import Any
|
||||
|
||||
from typing import Optional, Any, Dict
|
||||
|
||||
# See readme.md for instructions on running this code.
|
||||
|
||||
|
@ -34,11 +35,11 @@ class WikipediaHandler(object):
|
|||
should preface searches with "@mention-bot".
|
||||
@mention-bot <name of article>'''
|
||||
|
||||
def handle_message(self, message: dict, bot_handler: ExternalBotHandler) -> None:
|
||||
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
|
||||
bot_response = self.get_bot_wiki_response(message, bot_handler)
|
||||
bot_handler.send_reply(message, bot_response)
|
||||
|
||||
def get_bot_wiki_response(self, message: dict, bot_handler: ExternalBotHandler) -> Optional[str]:
|
||||
def get_bot_wiki_response(self, message: Dict[str, str], bot_handler: Any) -> Optional[str]:
|
||||
'''This function returns the URLs of the requested topic.'''
|
||||
|
||||
help_text = 'Please enter your search term after @mention-bot'
|
||||
|
|
|
@ -2,7 +2,8 @@ import random
|
|||
|
||||
import logging
|
||||
import requests
|
||||
from zulip_bots.lib import ExternalBotHandler
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
XKCD_TEMPLATE_URL = 'https://xkcd.com/%s/info.0.json'
|
||||
LATEST_XKCD_URL = 'https://xkcd.com/info.0.json'
|
||||
|
@ -33,7 +34,7 @@ class XkcdHandler(object):
|
|||
`<comic_id>`, e.g `@mention-bot 1234`.
|
||||
'''
|
||||
|
||||
def handle_message(self, message: dict, bot_handler: ExternalBotHandler) -> None:
|
||||
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
|
||||
xkcd_bot_response = get_xkcd_bot_response(message)
|
||||
bot_handler.send_reply(message, xkcd_bot_response)
|
||||
|
||||
|
@ -48,7 +49,7 @@ class XkcdNotFoundError(Exception):
|
|||
class XkcdServerError(Exception):
|
||||
pass
|
||||
|
||||
def get_xkcd_bot_response(message: dict) -> str:
|
||||
def get_xkcd_bot_response(message: Dict[str, str]) -> str:
|
||||
original_content = message['content'].strip()
|
||||
command = original_content.strip()
|
||||
|
||||
|
@ -83,7 +84,7 @@ def get_xkcd_bot_response(message: dict) -> str:
|
|||
fetched['alt'],
|
||||
fetched['img']))
|
||||
|
||||
def fetch_xkcd_query(mode: int, comic_id: str = None) -> dict:
|
||||
def fetch_xkcd_query(mode: int, comic_id: str = None) -> Dict[str, str]:
|
||||
try:
|
||||
if mode == XkcdBotCommand.LATEST: # Fetch the latest comic strip.
|
||||
url = LATEST_XKCD_URL
|
||||
|
|
|
@ -4,13 +4,14 @@ from __future__ import print_function
|
|||
import logging
|
||||
import ssl
|
||||
import sys
|
||||
from zulip_bots.lib import ExternalBotHandler
|
||||
try:
|
||||
import requests
|
||||
except ImportError as e:
|
||||
logging.error("Dependency missing!!\n{}".format(e))
|
||||
sys.exit(0)
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
HELP_MESSAGE = '''
|
||||
This bot allows users to translate a sentence into
|
||||
'Yoda speak'.
|
||||
|
@ -38,7 +39,7 @@ class YodaSpeakHandler(object):
|
|||
This bot will allow users to translate a sentence into 'Yoda speak'.
|
||||
It looks for messages starting with '@mention-bot'.
|
||||
'''
|
||||
def initialize(self, bot_handler: ExternalBotHandler) -> None:
|
||||
def initialize(self, bot_handler: Any) -> None:
|
||||
self.api_key = bot_handler.get_config_info('yoda')['api_key']
|
||||
|
||||
def usage(self) -> str:
|
||||
|
@ -55,7 +56,7 @@ class YodaSpeakHandler(object):
|
|||
@mention-bot You will learn how to speak like me someday.
|
||||
'''
|
||||
|
||||
def handle_message(self, message: dict, bot_handler: ExternalBotHandler) -> None:
|
||||
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
|
||||
self.handle_input(message, bot_handler)
|
||||
|
||||
def send_to_yoda_api(self, sentence: str) -> str:
|
||||
|
@ -88,7 +89,7 @@ class YodaSpeakHandler(object):
|
|||
sentence = message_content.replace(' ', '+')
|
||||
return sentence
|
||||
|
||||
def handle_input(self, message: dict, bot_handler: ExternalBotHandler) -> None:
|
||||
def handle_input(self, message: Dict[str, str], bot_handler: Any) -> None:
|
||||
original_content = message['content']
|
||||
|
||||
if self.is_help(original_content) or (original_content == ""):
|
||||
|
@ -113,7 +114,7 @@ class YodaSpeakHandler(object):
|
|||
|
||||
bot_handler.send_reply(message, reply_message)
|
||||
|
||||
def send_message(self, bot_handler: ExternalBotHandler, message: str, stream: str, subject: str) -> None:
|
||||
def send_message(self, bot_handler: Any, message: str, stream: str, subject: str) -> None:
|
||||
# function for sending a message
|
||||
bot_handler.send_message(dict(
|
||||
type='stream',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue