diff options
author | 2019-09-19 08:30:19 -0700 | |
---|---|---|
committer | 2019-09-19 08:30:19 -0700 | |
commit | 515d304f4a3a4a80630769d90a3ba8d912e8037b (patch) | |
tree | 82cfb6274a5277dc2905c6b9632e89a2868100d1 | |
parent | Replace incorrect None returns with Optional in certain commands (diff) |
Apply suggestions from code review
Co-Authored-By: Sebastiaan Zeeff <[email protected]>
-rw-r--r-- | bot/cogs/doc.py | 4 | ||||
-rw-r--r-- | bot/cogs/modlog.py | 4 | ||||
-rw-r--r-- | bot/cogs/off_topic_names.py | 2 | ||||
-rw-r--r-- | bot/cogs/reddit.py | 6 | ||||
-rw-r--r-- | bot/cogs/security.py | 2 | ||||
-rw-r--r-- | bot/cogs/utils.py | 2 | ||||
-rw-r--r-- | bot/cogs/wolfram.py | 2 | ||||
-rw-r--r-- | bot/decorators.py | 2 | ||||
-rw-r--r-- | bot/utils/__init__.py | 2 |
9 files changed, 13 insertions, 13 deletions
diff --git a/bot/cogs/doc.py b/bot/cogs/doc.py index 54a3172b8..2dcbad6e0 100644 --- a/bot/cogs/doc.py +++ b/bot/cogs/doc.py @@ -4,7 +4,7 @@ import logging import re import textwrap from collections import OrderedDict -from typing import Callable, Optional, Tuple +from typing import Any, Callable, Optional, Tuple import discord from bs4 import BeautifulSoup @@ -42,7 +42,7 @@ def async_cache(max_size: int = 128, arg_offset: int = 0) -> Callable: def decorator(function: Callable) -> Callable: """Define the async_cache decorator.""" @functools.wraps(function) - async def wrapper(*args) -> OrderedDict: + async def wrapper(*args) -> Any: """Decorator wrapper for the caching logic.""" key = ':'.join(args[arg_offset:]) diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py index d76804c34..2eb7b1eab 100644 --- a/bot/cogs/modlog.py +++ b/bot/cogs/modlog.py @@ -38,7 +38,7 @@ class ModLog(Cog, name="ModLog"): self._cached_deletes = [] self._cached_edits = [] - async def upload_log(self, messages: List[Message], actor_id: int) -> Optional[str]: + async def upload_log(self, messages: List[Message], actor_id: int) -> str: """ Uploads the log data to the database via an API endpoint for uploading logs. @@ -87,7 +87,7 @@ class ModLog(Cog, name="ModLog"): additional_embeds_msg: Optional[str] = None, timestamp_override: Optional[datetime] = None, footer: Optional[str] = None, - ) -> Optional[Message]: + ) -> Context: """Generate log embed and send to logging channel.""" embed = Embed(description=text) diff --git a/bot/cogs/off_topic_names.py b/bot/cogs/off_topic_names.py index a81b783d6..53e693b89 100644 --- a/bot/cogs/off_topic_names.py +++ b/bot/cogs/off_topic_names.py @@ -19,7 +19,7 @@ class OffTopicName(Converter): """A converter that ensures an added off-topic name is valid.""" @staticmethod - async def convert(ctx: Context, argument: str) -> None: + async def convert(ctx: Context, argument: str) -> str: """Attempt to replace any invalid characters with their approximate unicode equivalent.""" allowed_characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?'`-" diff --git a/bot/cogs/reddit.py b/bot/cogs/reddit.py index 2bc6fa58e..7bd11fb1b 100644 --- a/bot/cogs/reddit.py +++ b/bot/cogs/reddit.py @@ -3,7 +3,7 @@ import logging import random import textwrap from datetime import datetime, timedelta -from typing import Optional +from typing import List, Optional from discord import Colour, Embed, Message, TextChannel from discord.ext.commands import Bot, Cog, Context, group @@ -33,7 +33,7 @@ class Reddit(Cog): self.new_posts_task = None self.top_weekly_posts_task = None - async def fetch_posts(self, route: str, *, amount: int = 25, params: dict = None) -> dict: + async def fetch_posts(self, route: str, *, amount: int = 25, params: dict = None) -> List[dict]: """A helper method to fetch a certain amount of Reddit posts at a given route.""" # Reddit's JSON responses only provide 25 posts at most. if not 25 >= amount > 0: @@ -55,7 +55,7 @@ class Reddit(Cog): async def send_top_posts( self, channel: TextChannel, subreddit: Subreddit, content: str = None, time: str = "all" - ) -> Optional[Message]: + ) -> Message: """Create an embed for the top posts, then send it in a given TextChannel.""" # Create the new spicy embed. embed = Embed() diff --git a/bot/cogs/security.py b/bot/cogs/security.py index a04c18289..7274b8033 100644 --- a/bot/cogs/security.py +++ b/bot/cogs/security.py @@ -18,7 +18,7 @@ class Security(Cog): """Check if Context instance author is not a bot.""" return not ctx.author.bot - def check_on_guild(self, ctx: Context) -> Optional[bool]: + def check_on_guild(self, ctx: Context) -> bool: """Check if Context instance has a guild attribute.""" if ctx.guild is None: raise NoPrivateMessage("This command cannot be used in private messages.") diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index e27559efe..965d532a0 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -24,7 +24,7 @@ class Utils(Cog): self.base_github_pep_url = "https://raw.githubusercontent.com/python/peps/master/pep-" @command(name='pep', aliases=('get_pep', 'p')) - async def pep_command(self, ctx: Context, pep_number: str) -> Optional[Message]: + async def pep_command(self, ctx: Context, pep_number: str) -> None: """Fetches information about a PEP and sends it to the channel.""" if pep_number.isdigit(): pep_number = int(pep_number) diff --git a/bot/cogs/wolfram.py b/bot/cogs/wolfram.py index 1aa656a4b..ea9307352 100644 --- a/bot/cogs/wolfram.py +++ b/bot/cogs/wolfram.py @@ -52,7 +52,7 @@ async def send_embed( await ctx.send(embed=embed, file=f) -def custom_cooldown(*ignore: List[int]) -> check: +def custom_cooldown(*ignore: List[int]) -> Callable: """ Implement per-user and per-guild cooldowns for requests to the Wolfram API. diff --git a/bot/decorators.py b/bot/decorators.py index c953264b5..9a14d8df4 100644 --- a/bot/decorators.py +++ b/bot/decorators.py @@ -106,7 +106,7 @@ def redirect_output(destination_channel: int, bypass_roles: Container[int] = Non """ def wrap(func: Callable) -> Callable: @wraps(func) - async def inner(self: Callable, ctx: Context, *args, **kwargs) -> None: + async def inner(self: Callable, ctx: Context, *args, **kwargs) -> Any: if ctx.channel.id == destination_channel: log.trace(f"Command {ctx.command.name} was invoked in destination_channel, not redirecting") return await func(self, ctx, *args, **kwargs) diff --git a/bot/utils/__init__.py b/bot/utils/__init__.py index 618b90748..8184be824 100644 --- a/bot/utils/__init__.py +++ b/bot/utils/__init__.py @@ -18,7 +18,7 @@ class CaseInsensitiveDict(dict): """ @classmethod - def _k(cls, key: Hashable) -> Any: + def _k(cls, key: Hashable) -> Hashable: """Return lowered key if a string-like is passed, otherwise pass key straight through.""" return key.lower() if isinstance(key, str) else key |