From 745cd1d6d3d6227d2a1e82cf25611d76221c40cd Mon Sep 17 00:00:00 2001 From: decorator-factory <42166884+decorator-factory@users.noreply.github.com> Date: Sat, 7 Aug 2021 05:23:03 +0300 Subject: Fix type annotations --- bot/exts/evergreen/connect_four.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'bot/exts/evergreen/connect_four.py') diff --git a/bot/exts/evergreen/connect_four.py b/bot/exts/evergreen/connect_four.py index 5c82ffee..0f83bf8a 100644 --- a/bot/exts/evergreen/connect_four.py +++ b/bot/exts/evergreen/connect_four.py @@ -1,7 +1,7 @@ import asyncio import random -import typing from functools import partial +from typing import Optional, Union import discord import emojis @@ -14,8 +14,8 @@ from bot.constants import Emojis NUMBERS = list(Emojis.number_emojis.values()) CROSS_EMOJI = Emojis.incident_unactioned -Coordinate = typing.Optional[typing.Tuple[int, int]] -EMOJI_CHECK = typing.Union[discord.Emoji, str] +Coordinate = Optional[tuple[int, int]] +EMOJI_CHECK = Union[discord.Emoji, str] class Game: @@ -26,8 +26,8 @@ class Game: bot: Bot, channel: discord.TextChannel, player1: discord.Member, - player2: typing.Optional[discord.Member], - tokens: typing.List[str], + player2: Optional[discord.Member], + tokens: list[str], size: int = 7 ) -> None: @@ -48,7 +48,7 @@ class Game: self.player_inactive = None @staticmethod - def generate_board(size: int) -> typing.List[typing.List[int]]: + def generate_board(size: int) -> list[list[int]]: """Generate the connect 4 board.""" return [[0 for _ in range(size)] for _ in range(size)] @@ -185,7 +185,7 @@ class AI: self.game = game self.mention = bot.user.mention - def get_possible_places(self) -> typing.List[Coordinate]: + def get_possible_places(self) -> list[Coordinate]: """Gets all the coordinates where the AI could possibly place a counter.""" possible_coords = [] for column_num in range(self.game.grid_size): @@ -196,7 +196,7 @@ class AI: break return possible_coords - def check_ai_win(self, coord_list: typing.List[Coordinate]) -> typing.Optional[Coordinate]: + def check_ai_win(self, coord_list: list[Coordinate]) -> Optional[Coordinate]: """ Check AI win. @@ -209,7 +209,7 @@ class AI: if self.game.check_win(coords, 2): return coords - def check_player_win(self, coord_list: typing.List[Coordinate]) -> typing.Optional[Coordinate]: + def check_player_win(self, coord_list: list[Coordinate]) -> Optional[Coordinate]: """ Check Player win. @@ -223,11 +223,11 @@ class AI: return coords @staticmethod - def random_coords(coord_list: typing.List[Coordinate]) -> Coordinate: + def random_coords(coord_list: list[Coordinate]) -> Coordinate: """Picks a random coordinate from the possible ones.""" return random.choice(coord_list) - def play(self) -> typing.Union[Coordinate, bool]: + def play(self) -> Union[Coordinate, bool]: """ Plays for the AI. @@ -258,8 +258,8 @@ class ConnectFour(commands.Cog): def __init__(self, bot: Bot) -> None: self.bot = bot - self.games: typing.List[Game] = [] - self.waiting: typing.List[discord.Member] = [] + self.games: list[Game] = [] + self.waiting: list[discord.Member] = [] self.tokens = [":white_circle:", ":blue_circle:", ":red_circle:"] @@ -330,7 +330,7 @@ class ConnectFour(commands.Cog): @staticmethod def check_emojis( e1: EMOJI_CHECK, e2: EMOJI_CHECK - ) -> typing.Tuple[bool, typing.Optional[str]]: + ) -> tuple[bool, Optional[str]]: """Validate the emojis, the user put.""" if isinstance(e1, str) and emojis.count(e1) != 1: return False, e1 @@ -341,7 +341,7 @@ class ConnectFour(commands.Cog): async def _play_game( self, ctx: commands.Context, - user: typing.Optional[discord.Member], + user: Optional[discord.Member], board_size: int, emoji1: str, emoji2: str -- cgit v1.2.3 From aecc1e6f6f1df012add3ce394496b01e776bbfdf Mon Sep 17 00:00:00 2001 From: Xithrius Date: Wed, 1 Sep 2021 18:44:24 -0700 Subject: Removed None return annotation for any __init__ --- bot/exts/christmas/advent_of_code/_cog.py | 2 +- bot/exts/easter/egghead_quiz.py | 2 +- bot/exts/evergreen/avatar_modification/avatar_modify.py | 2 +- bot/exts/evergreen/battleship.py | 2 +- bot/exts/evergreen/connect_four.py | 4 ++-- bot/exts/evergreen/duck_game.py | 2 +- bot/exts/evergreen/error_handler.py | 2 +- bot/exts/evergreen/fun.py | 2 +- bot/exts/evergreen/minesweeper.py | 2 +- bot/exts/evergreen/recommend_game.py | 2 +- bot/exts/evergreen/trivia_quiz.py | 2 +- bot/exts/evergreen/xkcd.py | 2 +- bot/exts/halloween/spookynamerate.py | 2 +- bot/exts/internal_eval/_helpers.py | 6 +++--- bot/utils/checks.py | 2 +- bot/utils/randomization.py | 2 +- 16 files changed, 19 insertions(+), 19 deletions(-) (limited to 'bot/exts/evergreen/connect_four.py') diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py index 3d61753b..bc2ccc04 100644 --- a/bot/exts/christmas/advent_of_code/_cog.py +++ b/bot/exts/christmas/advent_of_code/_cog.py @@ -29,7 +29,7 @@ AOC_WHITELIST = AOC_WHITELIST_RESTRICTED + (Channels.advent_of_code,) class AdventOfCode(commands.Cog): """Advent of Code festivities! Ho Ho Ho!""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self._base_url = f"https://adventofcode.com/{AocConfig.year}" diff --git a/bot/exts/easter/egghead_quiz.py b/bot/exts/easter/egghead_quiz.py index 7c4960cd..ad550567 100644 --- a/bot/exts/easter/egghead_quiz.py +++ b/bot/exts/easter/egghead_quiz.py @@ -31,7 +31,7 @@ TIMELIMIT = 30 class EggheadQuiz(commands.Cog): """This cog contains the command for the Easter quiz!""" - def __init__(self) -> None: + def __init__(self): self.quiz_messages = {} @commands.command(aliases=("eggheadquiz", "easterquiz")) diff --git a/bot/exts/evergreen/avatar_modification/avatar_modify.py b/bot/exts/evergreen/avatar_modification/avatar_modify.py index 2be09be2..18202902 100644 --- a/bot/exts/evergreen/avatar_modification/avatar_modify.py +++ b/bot/exts/evergreen/avatar_modification/avatar_modify.py @@ -62,7 +62,7 @@ def file_safe_name(effect: str, display_name: str) -> str: class AvatarModify(commands.Cog): """Various commands for users to apply affects to their own avatars.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot async def _fetch_user(self, user_id: int) -> Optional[discord.User]: diff --git a/bot/exts/evergreen/battleship.py b/bot/exts/evergreen/battleship.py index 46694f6a..70d22a56 100644 --- a/bot/exts/evergreen/battleship.py +++ b/bot/exts/evergreen/battleship.py @@ -322,7 +322,7 @@ class Game: class Battleship(commands.Cog): """Play the classic game Battleship!""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self.games: list[Game] = [] self.waiting: list[discord.Member] = [] diff --git a/bot/exts/evergreen/connect_four.py b/bot/exts/evergreen/connect_four.py index 0f83bf8a..d4d80154 100644 --- a/bot/exts/evergreen/connect_four.py +++ b/bot/exts/evergreen/connect_four.py @@ -181,7 +181,7 @@ class Game: class AI: """The Computer Player for Single-Player games.""" - def __init__(self, bot: Bot, game: Game) -> None: + def __init__(self, bot: Bot, game: Game): self.game = game self.mention = bot.user.mention @@ -256,7 +256,7 @@ class AI: class ConnectFour(commands.Cog): """Connect Four. The Classic Vertical Four-in-a-row Game!""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self.games: list[Game] = [] self.waiting: list[discord.Member] = [] diff --git a/bot/exts/evergreen/duck_game.py b/bot/exts/evergreen/duck_game.py index 51e7a98a..614a234b 100644 --- a/bot/exts/evergreen/duck_game.py +++ b/bot/exts/evergreen/duck_game.py @@ -172,7 +172,7 @@ class DuckGame: class DuckGamesDirector(commands.Cog): """A cog for running Duck Duck Duck Goose games.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self.current_games = {} diff --git a/bot/exts/evergreen/error_handler.py b/bot/exts/evergreen/error_handler.py index 3fa8be39..fa9caffb 100644 --- a/bot/exts/evergreen/error_handler.py +++ b/bot/exts/evergreen/error_handler.py @@ -23,7 +23,7 @@ QUESTION_MARK_ICON = "https://cdn.discordapp.com/emojis/512367613339369475.png" class CommandErrorHandler(commands.Cog): """A error handler for the PythonDiscord server.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot @staticmethod diff --git a/bot/exts/evergreen/fun.py b/bot/exts/evergreen/fun.py index fd17a691..40743e7b 100644 --- a/bot/exts/evergreen/fun.py +++ b/bot/exts/evergreen/fun.py @@ -54,7 +54,7 @@ def caesar_cipher(text: str, offset: int) -> Iterable[str]: class Fun(Cog): """A collection of general commands for fun.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self._caesar_cipher_embed = json.loads(Path("bot/resources/evergreen/caesar_info.json").read_text("UTF-8")) diff --git a/bot/exts/evergreen/minesweeper.py b/bot/exts/evergreen/minesweeper.py index 75d13d88..a48b5051 100644 --- a/bot/exts/evergreen/minesweeper.py +++ b/bot/exts/evergreen/minesweeper.py @@ -51,7 +51,7 @@ class Game: class Minesweeper(commands.Cog): """Play a game of Minesweeper.""" - def __init__(self) -> None: + def __init__(self): self.games: dict[int, Game] = {} @commands.group(name="minesweeper", aliases=("ms",), invoke_without_command=True) diff --git a/bot/exts/evergreen/recommend_game.py b/bot/exts/evergreen/recommend_game.py index 66597b59..bdd3acb1 100644 --- a/bot/exts/evergreen/recommend_game.py +++ b/bot/exts/evergreen/recommend_game.py @@ -21,7 +21,7 @@ shuffle(game_recs) class RecommendGame(commands.Cog): """Commands related to recommending games.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self.index = 0 diff --git a/bot/exts/evergreen/trivia_quiz.py b/bot/exts/evergreen/trivia_quiz.py index d754cf02..aa4020d6 100644 --- a/bot/exts/evergreen/trivia_quiz.py +++ b/bot/exts/evergreen/trivia_quiz.py @@ -193,7 +193,7 @@ DYNAMIC_QUESTIONS_FORMAT_FUNCS = { class TriviaQuiz(commands.Cog): """A cog for all quiz commands.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self.game_status = {} # A variable to store the game status: either running or not running. diff --git a/bot/exts/evergreen/xkcd.py b/bot/exts/evergreen/xkcd.py index 7c4fc30e..b56c53d9 100644 --- a/bot/exts/evergreen/xkcd.py +++ b/bot/exts/evergreen/xkcd.py @@ -19,7 +19,7 @@ BASE_URL = "https://xkcd.com" class XKCD(Cog): """Retrieving XKCD comics.""" - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self.latest_comic_info: dict[str, Union[str, int]] = {} self.get_latest_comic_info.start() diff --git a/bot/exts/halloween/spookynamerate.py b/bot/exts/halloween/spookynamerate.py index bab79e56..5c21ead7 100644 --- a/bot/exts/halloween/spookynamerate.py +++ b/bot/exts/halloween/spookynamerate.py @@ -91,7 +91,7 @@ class SpookyNameRate(Cog): # will automatically start the scoring and announcing the result (without waiting for 12, so do not expect it to.). # Also, it won't wait for the two hours (when the poll closes). - def __init__(self, bot: Bot) -> None: + def __init__(self, bot: Bot): self.bot = bot self.name = None diff --git a/bot/exts/internal_eval/_helpers.py b/bot/exts/internal_eval/_helpers.py index 6fb07f61..5b2f8f5d 100644 --- a/bot/exts/internal_eval/_helpers.py +++ b/bot/exts/internal_eval/_helpers.py @@ -80,7 +80,7 @@ class EvalContext: clear the context, use the `.internal clear` command. """ - def __init__(self, context_vars: Namespace, local_vars: Namespace) -> None: + def __init__(self, context_vars: Namespace, local_vars: Namespace): self._locals = dict(local_vars) self.context_vars = dict(context_vars) @@ -182,7 +182,7 @@ class EvalContext: class WrapEvalCodeTree(ast.NodeTransformer): """Wraps the AST of eval code with the wrapper function.""" - def __init__(self, eval_code_tree: ast.AST, *args, **kwargs) -> None: + def __init__(self, eval_code_tree: ast.AST, *args, **kwargs): super().__init__(*args, **kwargs) self.eval_code_tree = eval_code_tree @@ -207,7 +207,7 @@ class WrapEvalCodeTree(ast.NodeTransformer): class CaptureLastExpression(ast.NodeTransformer): """Captures the return value from a loose expression.""" - def __init__(self, tree: ast.AST, *args, **kwargs) -> None: + def __init__(self, tree: ast.AST, *args, **kwargs): super().__init__(*args, **kwargs) self.tree = tree self.last_node = list(ast.iter_child_nodes(tree))[-1] diff --git a/bot/utils/checks.py b/bot/utils/checks.py index d5c06728..612d1ed6 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -22,7 +22,7 @@ log = logging.getLogger(__name__) class InWhitelistCheckFailure(CheckFailure): """Raised when the `in_whitelist` check fails.""" - def __init__(self, redirect_channel: Optional[int]) -> None: + def __init__(self, redirect_channel: Optional[int]): self.redirect_channel = redirect_channel if redirect_channel: diff --git a/bot/utils/randomization.py b/bot/utils/randomization.py index 3360ef44..c9eabbd2 100644 --- a/bot/utils/randomization.py +++ b/bot/utils/randomization.py @@ -11,7 +11,7 @@ class RandomCycle: The iterable is reshuffled after each full cycle. """ - def __init__(self, iterable: Iterable) -> None: + def __init__(self, iterable: Iterable): self.iterable = list(iterable) self.index = itertools.cycle(range(len(iterable))) -- cgit v1.2.3 From 3a7219939585e82980b59c0c8ff7d710a7021795 Mon Sep 17 00:00:00 2001 From: Xithrius Date: Thu, 2 Sep 2021 10:13:35 -0700 Subject: Removed unecessary `None` annotation --- bot/exts/evergreen/connect_four.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot/exts/evergreen/connect_four.py') diff --git a/bot/exts/evergreen/connect_four.py b/bot/exts/evergreen/connect_four.py index d4d80154..647bb2b7 100644 --- a/bot/exts/evergreen/connect_four.py +++ b/bot/exts/evergreen/connect_four.py @@ -29,8 +29,7 @@ class Game: player2: Optional[discord.Member], tokens: list[str], size: int = 7 - ) -> None: - + ): self.bot = bot self.channel = channel self.player1 = player1 -- cgit v1.2.3