Remove self: Any mypy annotations

This commit is contained in:
fredfishgames 2017-12-08 16:39:59 +00:00 committed by showell
parent 5f70e17259
commit 4c4a60d90f
8 changed files with 26 additions and 26 deletions

View file

@ -13,7 +13,7 @@ class FollowupHandler(object):
external issue tracker as well. external issue tracker as well.
''' '''
def usage(self: Any) -> str: def usage(self) -> str:
return ''' return '''
This plugin will allow users to flag messages This plugin will allow users to flag messages
as being follow-up items. Users should preface as being follow-up items. Users should preface
@ -23,7 +23,7 @@ class FollowupHandler(object):
called "followup" that your API user can send to. called "followup" that your API user can send to.
''' '''
def handle_message(self: Any, message: Dict[str, str], bot_handler: Any) -> None: def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
if message['content'] == '': if message['content'] == '':
bot_response = "Please specify the message you want to send to followup stream after @mention-bot" bot_response = "Please specify the message you want to send to followup stream after @mention-bot"
bot_handler.send_reply(message, bot_response) bot_handler.send_reply(message, bot_response)
@ -36,7 +36,7 @@ class FollowupHandler(object):
content=bot_response, content=bot_response,
)) ))
def get_bot_followup_response(self: Any, message: Dict[str, str]) -> str: def get_bot_followup_response(self, message: Dict[str, str]) -> str:
original_content = message['content'] original_content = message['content']
original_sender = message['sender_email'] original_sender = message['sender_email']
temp_content = 'from %s: ' % (original_sender,) temp_content = 'from %s: ' % (original_sender,)

View file

@ -10,7 +10,7 @@ from typing import Any
class TestFollowUpBot(BotTestCase): class TestFollowUpBot(BotTestCase):
bot_name = "followup" bot_name = "followup"
def test_bot(self: Any) -> None: def test_bot(self) -> None:
expected_send_reply = [ expected_send_reply = [
("", 'Please specify the message you want to send to followup stream after @mention-bot') ("", 'Please specify the message you want to send to followup stream after @mention-bot')
] ]

View file

@ -21,17 +21,17 @@ class GiphyHandler(object):
and responds with a message with the GIF based on provided keywords. and responds with a message with the GIF based on provided keywords.
It also responds to private messages. It also responds to private messages.
''' '''
def usage(self: Any) -> str: def usage(self) -> str:
return ''' return '''
This plugin allows users to post GIFs provided by Giphy. This plugin allows users to post GIFs provided by Giphy.
Users should preface keywords with the Giphy-bot @mention. Users should preface keywords with the Giphy-bot @mention.
The bot responds also to private messages. The bot responds also to private messages.
''' '''
def initialize(self: Any, bot_handler: Any) -> None: def initialize(self, bot_handler: Any) -> None:
self.config_info = bot_handler.get_config_info('giphy') self.config_info = bot_handler.get_config_info('giphy')
def handle_message(self: Any, message: Dict[str, str], bot_handler: Any) -> None: def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
bot_response = get_bot_giphy_response( bot_response = get_bot_giphy_response(
message, message,
bot_handler, bot_handler,

View file

@ -9,7 +9,7 @@ from zulip_bots.test_lib import StubBotHandler, StubBotTestCase, get_bot_message
class TestGiphyBot(StubBotTestCase): class TestGiphyBot(StubBotTestCase):
bot_name = "giphy" bot_name = "giphy"
def test_normal(self: Any) -> None: def test_normal(self) -> None:
bot_response = '[Click to enlarge]' \ bot_response = '[Click to enlarge]' \
'(https://media4.giphy.com/media/3o6ZtpxSZbQRRnwCKQ/giphy.gif)' \ '(https://media4.giphy.com/media/3o6ZtpxSZbQRRnwCKQ/giphy.gif)' \
'[](/static/images/interactive-bot/giphy/powered-by-giphy.png)' '[](/static/images/interactive-bot/giphy/powered-by-giphy.png)'
@ -18,7 +18,7 @@ class TestGiphyBot(StubBotTestCase):
self.mock_http_conversation('test_normal'): self.mock_http_conversation('test_normal'):
self.verify_reply('Hello', bot_response) self.verify_reply('Hello', bot_response)
def test_no_result(self: Any) -> None: def test_no_result(self) -> None:
with self.mock_config_info({'key': '12345678'}), \ with self.mock_config_info({'key': '12345678'}), \
self.mock_http_conversation('test_no_result'): self.mock_http_conversation('test_no_result'):
self.verify_reply( self.verify_reply(
@ -26,7 +26,7 @@ class TestGiphyBot(StubBotTestCase):
'Sorry, I don\'t have a GIF for "world without zulip"! :astonished:', 'Sorry, I don\'t have a GIF for "world without zulip"! :astonished:',
) )
def test_403(self: Any) -> None: def test_403(self) -> None:
bot = get_bot_message_handler(self.bot_name) bot = get_bot_message_handler(self.bot_name)
bot_handler = StubBotHandler() bot_handler = StubBotHandler()
@ -42,7 +42,7 @@ class TestGiphyBot(StubBotTestCase):
# but an exception. # but an exception.
bot.handle_message(mock_message, bot_handler) bot.handle_message(mock_message, bot_handler)
def test_connection_error(self: Any) -> None: def test_connection_error(self) -> None:
with self.mock_config_info({'key': '12345678'}), \ with self.mock_config_info({'key': '12345678'}), \
patch('requests.get', side_effect=ConnectionError()), \ patch('requests.get', side_effect=ConnectionError()), \
patch('logging.warning'): patch('logging.warning'):

View file

@ -17,19 +17,19 @@ class GithubHandler(object):
GITHUB_ISSUE_URL_TEMPLATE = 'https://api.github.com/repos/{owner}/{repo}/issues/{id}' GITHUB_ISSUE_URL_TEMPLATE = 'https://api.github.com/repos/{owner}/{repo}/issues/{id}'
HANDLE_MESSAGE_REGEX = re.compile("(?:([\w-]+)\/)?([\w-]+)?#(\d+)") HANDLE_MESSAGE_REGEX = re.compile("(?:([\w-]+)\/)?([\w-]+)?#(\d+)")
def initialize(self: Any, bot_handler: Any) -> None: def initialize(self, bot_handler: Any) -> None:
self.config_info = bot_handler.get_config_info('github_detail', optional=True) self.config_info = bot_handler.get_config_info('github_detail', optional=True)
self.owner = self.config_info.get("owner", False) self.owner = self.config_info.get("owner", False)
self.repo = self.config_info.get("repo", False) self.repo = self.config_info.get("repo", False)
def usage(self: Any) -> str: def usage(self) -> str:
return ("This plugin displays details on github issues and pull requests. " return ("This plugin displays details on github issues and pull requests. "
"To reference an issue or pull request usename mention the bot then " "To reference an issue or pull request usename mention the bot then "
"anytime in the message type its id, for example:\n" "anytime in the message type its id, for example:\n"
"@**Github detail** #3212 zulip#3212 zulip/zulip#3212\n" "@**Github detail** #3212 zulip#3212 zulip/zulip#3212\n"
"The default owner is {} and the default repo is {}.".format(self.owner, self.repo)) "The default owner is {} and the default repo is {}.".format(self.owner, self.repo))
def format_message(self: Any, details: Dict[str, Any]) -> str: def format_message(self, details: Dict[str, Any]) -> str:
number = details['number'] number = details['number']
title = details['title'] title = details['title']
link = details['html_url'] link = details['html_url']
@ -46,7 +46,7 @@ class GithubHandler(object):
'Status - **{status}**\n```quote\n{description}\n```'.format(status=status, description=description)) 'Status - **{status}**\n```quote\n{description}\n```'.format(status=status, description=description))
return ''.join(message_string) return ''.join(message_string)
def get_details_from_github(self: Any, owner: str, repo: str, number: str) -> Union[None, Dict[str, Union[str, int, bool]]]: def get_details_from_github(self, owner: str, repo: str, number: str) -> Union[None, Dict[str, Union[str, int, bool]]]:
# Gets the details of an issues or pull request # Gets the details of an issues or pull request
try: try:
r = requests.get( r = requests.get(
@ -58,7 +58,7 @@ class GithubHandler(object):
return None return None
return r.json() return r.json()
def get_owner_and_repo(self: Any, issue_pr: Any) -> Tuple[str, str]: def get_owner_and_repo(self, issue_pr: Any) -> Tuple[str, str]:
owner = issue_pr.group(1) owner = issue_pr.group(1)
repo = issue_pr.group(2) repo = issue_pr.group(2)
if owner is None: if owner is None:
@ -67,7 +67,7 @@ class GithubHandler(object):
repo = self.repo repo = self.repo
return (owner, repo) return (owner, repo)
def handle_message(self: Any, message: Dict[str, str], bot_handler: Any) -> None: def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
# Send help message # Send help message
if message['content'] == 'help': if message['content'] == 'help':
bot_handler.send_reply(message, self.usage()) bot_handler.send_reply(message, self.usage())

View file

@ -13,7 +13,7 @@ class TestGithubDetailBot(StubBotTestCase):
mock_config = {'owner': 'zulip', 'repo': 'zulip'} mock_config = {'owner': 'zulip', 'repo': 'zulip'}
# Overrides default test_bot_usage(). # Overrides default test_bot_usage().
def test_bot_usage(self: Any) -> None: def test_bot_usage(self) -> None:
bot = get_bot_message_handler(self.bot_name) bot = get_bot_message_handler(self.bot_name)
bot_handler = StubBotHandler() bot_handler = StubBotHandler()
@ -22,7 +22,7 @@ class TestGithubDetailBot(StubBotTestCase):
self.assertIn('displays details on github issues', bot.usage()) self.assertIn('displays details on github issues', bot.usage())
def test_issue(self: Any) -> None: def test_issue(self) -> None:
request = 'zulip/zulip#5365' request = 'zulip/zulip#5365'
bot_response = '**[zulip/zulip#5365](https://github.com/zulip/zulip/issues/5365)'\ bot_response = '**[zulip/zulip#5365](https://github.com/zulip/zulip/issues/5365)'\
' - frontend: Enable hot-reloading of CSS in development**\n'\ ' - frontend: Enable hot-reloading of CSS in development**\n'\
@ -38,7 +38,7 @@ class TestGithubDetailBot(StubBotTestCase):
with self.mock_config_info(self.mock_config): with self.mock_config_info(self.mock_config):
self.verify_reply(request, bot_response) self.verify_reply(request, bot_response)
def test_pull_request(self: Any) -> None: def test_pull_request(self) -> None:
request = 'zulip/zulip#5345' request = 'zulip/zulip#5345'
bot_response = '**[zulip/zulip#5345](https://github.com/zulip/zulip/pull/5345)'\ bot_response = '**[zulip/zulip#5345](https://github.com/zulip/zulip/pull/5345)'\
' - [WIP] modal: Replace bootstrap modal with custom modal class**\n'\ ' - [WIP] modal: Replace bootstrap modal with custom modal class**\n'\
@ -55,20 +55,20 @@ class TestGithubDetailBot(StubBotTestCase):
with self.mock_config_info(self.mock_config): with self.mock_config_info(self.mock_config):
self.verify_reply(request, bot_response) self.verify_reply(request, bot_response)
def test_404(self: Any) -> None: def test_404(self) -> None:
request = 'zulip/zulip#0' request = 'zulip/zulip#0'
bot_response = 'Failed to find issue/pr: zulip/zulip#0' bot_response = 'Failed to find issue/pr: zulip/zulip#0'
with self.mock_http_conversation('test_404'): with self.mock_http_conversation('test_404'):
with self.mock_config_info(self.mock_config): with self.mock_config_info(self.mock_config):
self.verify_reply(request, bot_response) self.verify_reply(request, bot_response)
def test_random_text(self: Any) -> None: def test_random_text(self) -> None:
request = 'some random text' request = 'some random text'
bot_response = 'Failed to find any issue or PR.' bot_response = 'Failed to find any issue or PR.'
with self.mock_config_info(self.mock_config): with self.mock_config_info(self.mock_config):
self.verify_reply(request, bot_response) self.verify_reply(request, bot_response)
def test_help_text(self: Any) -> None: def test_help_text(self) -> None:
request = 'help' request = 'help'
bot_response = 'This plugin displays details on github issues and pull requests. '\ bot_response = 'This plugin displays details on github issues and pull requests. '\
'To reference an issue or pull request usename mention the bot then '\ 'To reference an issue or pull request usename mention the bot then '\

View file

@ -2,7 +2,7 @@
from typing import Any, Dict from typing import Any, Dict
class HelpHandler(object): class HelpHandler(object):
def usage(self: Any) -> str: def usage(self) -> str:
return ''' return '''
This plugin will give info about Zulip to This plugin will give info about Zulip to
any user that types a message saying "help". any user that types a message saying "help".
@ -12,7 +12,7 @@ class HelpHandler(object):
your Zulip instance. your Zulip instance.
''' '''
def handle_message(self: Any, message: Dict[str, str], bot_handler: Any) -> None: def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
help_content = "Info on Zulip can be found here:\nhttps://github.com/zulip/zulip" help_content = "Info on Zulip can be found here:\nhttps://github.com/zulip/zulip"
bot_handler.send_reply(message, help_content) bot_handler.send_reply(message, help_content)

View file

@ -7,7 +7,7 @@ from typing import Any
class TestHelpBot(StubBotTestCase): class TestHelpBot(StubBotTestCase):
bot_name = "help" bot_name = "help"
def test_bot(self: Any) -> None: def test_bot(self) -> None:
help_text = "Info on Zulip can be found here:\nhttps://github.com/zulip/zulip" help_text = "Info on Zulip can be found here:\nhttps://github.com/zulip/zulip"
requests = ["", "help", "Hi, my name is abc"] requests = ["", "help", "Hi, my name is abc"]