Skip to content

Commit

Permalink
mypy: Enable explicit-override error.
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk committed Oct 26, 2023
1 parent 43654b9 commit 3de904e
Show file tree
Hide file tree
Showing 28 changed files with 83 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enable_error_code = [
"truthy-iterable",
"ignore-without-code",
"unused-awaitable",
"explicit-override",
]

# Other options.
Expand Down
3 changes: 3 additions & 0 deletions zulip/integrations/bridge_with_matrix/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from unittest import TestCase, mock

import nio
from typing_extensions import override

from .matrix_bridge import MatrixToZulip, ZulipToMatrix, read_configuration

Expand Down Expand Up @@ -183,6 +184,7 @@ class MatrixBridgeMatrixToZulipTests(TestCase):
room = mock.MagicMock()
room.user_name = lambda _: "John Smith"

@override
def setUp(self) -> None:
self.matrix_to_zulip = mock.MagicMock()
self.matrix_to_zulip.get_message_content_from_event = (
Expand Down Expand Up @@ -229,6 +231,7 @@ class MatrixBridgeZulipToMatrixTests(TestCase):
subject=valid_zulip_config["topic"],
)

@override
def setUp(self) -> None:
self.zulip_to_matrix = mock.MagicMock()
self.zulip_to_matrix.zulip_config = self.valid_zulip_config
Expand Down
2 changes: 2 additions & 0 deletions zulip/integrations/rss/rss-bot
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from html.parser import HTMLParser
from typing import Any, Dict, List, Optional, Tuple

import feedparser
from typing_extensions import override

import zulip

Expand Down Expand Up @@ -138,6 +139,7 @@ class MLStripper(HTMLParser):
self.reset()
self.fed: List[str] = []

@override
def handle_data(self, data: str) -> None:
self.fed.append(data)

Expand Down
3 changes: 3 additions & 0 deletions zulip/integrations/zephyr/zephyr_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
c_void_p,
)

from typing_extensions import override

libc = CDLL("libc.so.6")
com_err = CDLL("libcom_err.so.2")
libzephyr = CDLL("libzephyr.so.4")
Expand Down Expand Up @@ -198,6 +200,7 @@ class ZephyrError(Exception):
def __init__(self, code: int) -> None:
self.code = code

@override
def __str__(self) -> str:
return error_message(self.code).decode()

Expand Down
4 changes: 3 additions & 1 deletion zulip/zulip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import distro
import requests
from typing_extensions import Literal
from typing_extensions import Literal, override

__version__ = "0.8.2"

Expand Down Expand Up @@ -125,6 +125,7 @@ def _check_success_timeout(self) -> None:


class RandomExponentialBackoff(CountingBackoff):
@override
def fail(self) -> None:
super().fail()
# Exponential growth with ratio sqrt(2); compute random delay
Expand Down Expand Up @@ -1802,6 +1803,7 @@ def hash_util_decode(string: str) -> str:
# This block is support for testing Zulip 3.x, which documents old
# interfaces for the following functions:
class LegacyInterfaceClient(Client):
@override
def update_user_group_members(self, group_data: Dict[str, Any]) -> Dict[str, Any]: # type: ignore[override] # Intentional override; see comments above.
modern_group_data = group_data.copy()
group_id = group_data["group_id"]
Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/baremetrics/test_baremetrics.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.bots.baremetrics.baremetrics import BaremetricsHandler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler


class TestBaremetricsBot(BotTestCase, DefaultTests):
bot_name = "baremetrics"

@override
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"api_key": "TEST"}), patch("requests.get"):
self.verify_reply("", "No Command Specified")
Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/chessbot/test_chessbot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing_extensions import override

from zulip_bots.test_lib import BotTestCase, DefaultTests


Expand Down Expand Up @@ -107,6 +109,7 @@ class TestChessBot(BotTestCase, DefaultTests):
h g f e d c b a
```"""

@override
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"stockfish_location": "/foo/bar"}):
response = self.get_response(dict(content=""))
Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Dict, List

from typing_extensions import override

from zulip_bots.bots.connect_four.controller import ConnectFourModel
from zulip_bots.game_handler import BadMoveException
from zulip_bots.test_lib import BotTestCase, DefaultTests
Expand All @@ -8,6 +10,7 @@
class TestConnectFourBot(BotTestCase, DefaultTests):
bot_name = "connect_four"

@override
def make_request_message(
self, content: str, user: str = "[email protected]", user_name: str = "foo"
) -> Dict[str, str]:
Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import ByteString, Iterator
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.test_file_utils import read_bot_fixture_data
from zulip_bots.test_lib import BotTestCase, DefaultTests

Expand Down Expand Up @@ -71,6 +73,7 @@ def test_help(self) -> None:
def test_alternate_response(self) -> None:
self._test("test_alternate_result", "hello", "alternate result")

@override
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"key": "abcdefg", "bot_info": "bot info foo bar"}):
pass
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/followup/test_followup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing_extensions import override

from zulip_bots.test_lib import BotTestCase, DefaultTests


Expand Down Expand Up @@ -30,6 +32,7 @@ def test_different_stream(self) -> None:
self.assertEqual(response["content"], "from [email protected]: feed the cat")
self.assertEqual(response["to"], "issue")

@override
def test_bot_responds_to_empty_message(self) -> None:
bot_response = (
"Please specify the message you want to send to followup stream after @mention-bot"
Expand Down
6 changes: 6 additions & 0 deletions zulip_bots/zulip_bots/bots/front/test_front.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from typing import Any, Dict, Optional

from typing_extensions import override

from zulip_bots.test_lib import BotTestCase, DefaultTests


class TestFrontBot(BotTestCase, DefaultTests):
bot_name = "front"

@override
def make_request_message(self, content: str) -> Dict[str, Any]:
message = super().make_request_message(content)
message["subject"] = "cnv_kqatm2"
Expand All @@ -18,6 +21,7 @@ def test_bot_invalid_api_key(self) -> None:
with self.assertRaises(KeyError):
bot, bot_handler = self._get_handlers()

@override
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"api_key": "TEST"}):
self.verify_reply("", "Unknown command. Use `help` for instructions.")
Expand Down Expand Up @@ -87,11 +91,13 @@ def _test_command_error(self, command_name: str, command_arg: Optional[str] = No
class TestFrontBotWrongTopic(BotTestCase, DefaultTests):
bot_name = "front"

@override
def make_request_message(self, content: str) -> Dict[str, Any]:
message = super().make_request_message(content)
message["subject"] = "kqatm2"
return message

@override
def test_bot_responds_to_empty_message(self) -> None:
pass

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from typing import Any, Dict, List
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.game_handler import GameInstance
from zulip_bots.test_lib import BotTestCase, DefaultTests


class TestGameHandlerBot(BotTestCase, DefaultTests):
bot_name = "game_handler_bot"

@override
def make_request_message(
self,
content: str,
Expand Down
2 changes: 2 additions & 0 deletions zulip_bots/zulip_bots/bots/giphy/test_giphy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest.mock import patch

from requests.exceptions import ConnectionError
from typing_extensions import override

from zulip_bots.test_file_utils import get_bot_message_handler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
Expand All @@ -10,6 +11,7 @@ class TestGiphyBot(BotTestCase, DefaultTests):
bot_name = "giphy"

# Test for bot response to empty message
@override
def test_bot_responds_to_empty_message(self) -> None:
bot_response = (
"[Click to enlarge]"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing_extensions import override

from zulip_bots.test_file_utils import get_bot_message_handler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler

Expand All @@ -8,6 +10,7 @@ class TestGithubDetailBot(BotTestCase, DefaultTests):
empty_config = {"owner": "", "repo": ""}

# Overrides default test_bot_usage().
@override
def test_bot_usage(self) -> None:
bot = get_bot_message_handler(self.bot_name)
bot_handler = StubBotHandler()
Expand All @@ -18,6 +21,7 @@ def test_bot_usage(self) -> None:
self.assertIn("displays details on github issues", bot.usage())

# Override default function in BotTestCase
@override
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info(self.mock_config):
self.verify_reply("", "Failed to find any issue or PR.")
Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/idonethis/test_idonethis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.test_lib import BotTestCase, DefaultTests


Expand Down Expand Up @@ -112,6 +114,7 @@ def test_entries_list(self) -> None:
" * ID: 72c8241d2218464433268c5abd6625ac104e3d8f",
)

@override
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info(
{"api_key": "12345678", "bot_info": "team"}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.bots.link_shortener.link_shortener import LinkShortenerHandler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler

Expand All @@ -11,6 +13,7 @@ def _test(self, message: str, response: str) -> None:
with self.mock_config_info({"key": "qwertyuiop"}):
self.verify_reply(message, response)

@override
def test_bot_responds_to_empty_message(self) -> None:
with patch("requests.get"):
self._test(
Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/mention/test_mention.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.bots.mention.mention import MentionHandler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler


class TestMentionBot(BotTestCase, DefaultTests):
bot_name = "mention"

@override
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info({"access_token": "12345"}), patch("requests.get"):
self.verify_reply("", "Empty Mention Query")
Expand Down
2 changes: 2 additions & 0 deletions zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch

from simple_salesforce.exceptions import SalesforceAuthenticationFailed
from typing_extensions import override

from zulip_bots.test_file_utils import read_bot_fixture_data
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler
Expand Down Expand Up @@ -111,6 +112,7 @@ def _test_initialize(self, auth_success: bool = True) -> None:
), mock_salesforce_commands_types():
bot, bot_handler = self._get_handlers()

@override
def test_bot_responds_to_empty_message(self) -> None:
self._test("test_one_result", "", help_text)

Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/tictactoe/tictactoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import random
from typing import Any, List, Tuple

from typing_extensions import override

from zulip_bots.game_handler import BadMoveException, GameAdapter

# -------------------------------------
Expand Down Expand Up @@ -267,6 +269,7 @@ class ticTacToeHandler(GameAdapter):
"description": "Lets you play Tic-tac-toe against a computer.",
}

@override
def usage(self) -> str:
return """
You can play tic-tac-toe now! Make sure your
Expand Down
4 changes: 4 additions & 0 deletions zulip_bots/zulip_bots/bots/trello/test_trello.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.bots.trello.trello import TrelloHandler
from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler

Expand All @@ -9,10 +11,12 @@
class TestTrelloBot(BotTestCase, DefaultTests):
bot_name: str = "trello"

@override
def test_bot_responds_to_empty_message(self) -> None:
with self.mock_config_info(mock_config), patch("requests.get"):
self.verify_reply("", "Empty Query")

@override
def test_bot_usage(self) -> None:
with self.mock_config_info(mock_config), patch("requests.get"):
self.verify_reply(
Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/trivia_quiz/test_trivia_quiz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Any, Dict, Optional, Tuple
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.bots.trivia_quiz.trivia_quiz import (
fix_quotes,
get_quiz_from_id,
Expand Down Expand Up @@ -41,6 +43,7 @@ def _test(self, message: str, response: str, fixture: Optional[str] = None) -> N
else:
self.verify_reply(message, response)

@override
def test_bot_responds_to_empty_message(self) -> None:
self._test("", 'type "new" for a new question')

Expand Down
3 changes: 3 additions & 0 deletions zulip_bots/zulip_bots/bots/weather/test_weather.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Optional
from unittest.mock import patch

from typing_extensions import override

from zulip_bots.test_lib import BotTestCase, DefaultTests


Expand All @@ -26,6 +28,7 @@ def _test(self, message: str, response: str, fixture: Optional[str] = None) -> N
self.verify_reply(message, response)

# Override default function in BotTestCase
@override
def test_bot_responds_to_empty_message(self) -> None:
with patch("requests.get"):
self._test("", self.help_content)
Expand Down
Loading

0 comments on commit 3de904e

Please sign in to comment.