Skip to content

Commit 638e2f1

Browse files
committed
Fix typing errors
1 parent 2549c23 commit 638e2f1

File tree

11 files changed

+171
-50
lines changed

11 files changed

+171
-50
lines changed

cogs/command_error.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,31 @@ async def on_application_command_error(
6868
if isinstance(error, discord.ApplicationCommandInvokeError) and isinstance(
6969
error.original, GuildDoesNotExistError
7070
):
71-
command_name: str = (
72-
ctx.command.callback.__name__
73-
if (
74-
hasattr(ctx.command, "callback")
75-
and not ctx.command.callback.__name__.startswith("_")
71+
command_name: str | None = (
72+
(
73+
ctx.command.callback.__name__
74+
if (
75+
hasattr(ctx.command, "callback")
76+
and not ctx.command.callback.__name__.startswith("_")
77+
)
78+
else ctx.command.qualified_name
7679
)
77-
else ctx.command.qualified_name
80+
if ctx.command is not None
81+
else None
7882
)
7983
logger.critical(
8084
" ".join(
8185
message_part
8286
for message_part in (
8387
error.original.ERROR_CODE,
84-
f"({command_name})" if command_name in self.ERROR_ACTIVITIES else "",
88+
(
89+
f"({command_name})"
90+
if (
91+
command_name is not None
92+
and command_name in self.ERROR_ACTIVITIES
93+
)
94+
else ""
95+
),
8596
str(error.original).rstrip(".:"),
8697
)
8798
if message_part

cogs/committee_actions_tracking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ async def action_all_committee(
556556
async def list_user_actions( # NOTE: Committee role check is not present because non-committee can have actions, and need to be able to list their own actions.
557557
self,
558558
ctx: "TeXBotApplicationContext",
559-
action_member_id: None | str,
559+
action_member_id: "None | str",
560560
ping: bool, # noqa: FBT001
561-
status: None | str,
561+
status: "None | str",
562562
) -> None:
563563
"""
564564
Definition and callback of the "/list" command.

cogs/induct.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ async def _perform_induction(
239239
applicant_role, reason=INDUCT_AUDIT_MESSAGE
240240
)
241241

242-
tex_emoji: discord.Emoji | None = self.bot.get_emoji(743218410409820213)
242+
tex_emoji: discord.Emoji | discord.AppEmoji | None = self.bot.get_emoji(
243+
743218410409820213
244+
)
243245
if not tex_emoji:
244246
tex_emoji = discord.utils.get(main_guild.emojis, name="TeX")
245247

cogs/kill.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
if TYPE_CHECKING:
1313
from collections.abc import Sequence
1414
from logging import Logger
15-
from typing import Final
15+
from typing import Final, Never
1616

1717
from utils import TeXBotApplicationContext
1818

@@ -27,17 +27,17 @@ class ConfirmKillView(View):
2727
@discord.ui.button(
2828
label="SHUTDOWN", style=discord.ButtonStyle.red, custom_id="shutdown_confirm"
2929
)
30-
async def confirm_shutdown_button_callback( # type: ignore[misc]
31-
self, _: discord.Button, interaction: discord.Interaction
30+
async def confirm_shutdown_button_callback(
31+
self, _: "discord.ui.Button[Never]", interaction: discord.Interaction
3232
) -> None:
3333
"""When the shutdown button is pressed, delete the message."""
3434
logger.debug('"Confirm" button pressed. %s', interaction)
3535

3636
@discord.ui.button(
3737
label="CANCEL", style=discord.ButtonStyle.grey, custom_id="shutdown_cancel"
3838
)
39-
async def cancel_shutdown_button_callback( # type: ignore[misc]
40-
self, _: discord.Button, interaction: discord.Interaction
39+
async def cancel_shutdown_button_callback(
40+
self, _: "discord.ui.Button[Never]", interaction: discord.Interaction
4141
) -> None:
4242
"""When the cancel button is pressed, delete the message."""
4343
logger.debug('"Cancel" button pressed. %s', interaction)

cogs/make_applicant.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ async def _perform_make_applicant(
6262
await applicant_member.add_roles(applicant_role, reason=AUDIT_MESSAGE)
6363
logger.debug("Applicant role given to user %s", applicant_member)
6464

65-
tex_emoji: discord.Emoji | None = self.bot.get_emoji(743218410409820213)
65+
tex_emoji: discord.Emoji | discord.AppEmoji | None = self.bot.get_emoji(
66+
743218410409820213
67+
)
6668
if not tex_emoji:
6769
tex_emoji = discord.utils.get(main_guild.emojis, name="TeX")
6870

cogs/make_member.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async def make_member(
109109
)
110110

111111
if not re.fullmatch(r"\A\d{7}\Z", raw_group_member_id):
112-
await self.command_send_error(ctx, message=(INVALID_GROUP_MEMBER_ID_MESSAGE))
112+
await self.command_send_error(ctx, message=INVALID_GROUP_MEMBER_ID_MESSAGE)
113113
return
114114

115115
try:
@@ -195,6 +195,7 @@ async def make_member(
195195
guest_role,
196196
reason=f'{ctx.user} used TeX Bot slash-command: "/make-member"',
197197
)
198+
198199
applicant_role: discord.Role | None
199200
try:
200201
applicant_role = await ctx.bot.applicant_role

cogs/remind_me.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ async def remind_me(
210210
211211
The "remind_me" command responds with the given message after the specified time.
212212
"""
213+
if ctx.channel is None:
214+
CTX_CHANNEL_IS_NONE_MESSAGE: Final[str] = (
215+
"Cannot create reminder where `ctx.channel` is `None`."
216+
)
217+
raise TypeError(CTX_CHANNEL_IS_NONE_MESSAGE)
218+
213219
parsed_time: tuple[time.struct_time, int] = parsedatetime.Calendar().parseDT(
214220
delay, tzinfo=timezone.get_current_timezone()
215221
)

cogs/send_introduction_reminders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
if TYPE_CHECKING:
2929
from collections.abc import Sequence
3030
from logging import Logger
31-
from typing import Final
31+
from typing import Final, Never
3232

3333
from utils import TeXBot
3434

@@ -231,8 +231,8 @@ async def send_error(
231231
style=discord.ButtonStyle.red,
232232
emoji=discord.PartialEmoji.from_str(emoji.emojize(":no_good:", language="alias")),
233233
)
234-
async def opt_out_introduction_reminders_button_callback( # type: ignore[misc]
235-
self, button: discord.Button, interaction: discord.Interaction
234+
async def opt_out_introduction_reminders_button_callback(
235+
self, button: "discord.ui.Button[Never]", interaction: discord.Interaction
236236
) -> None:
237237
"""
238238
Set the opt-in/out flag depending on the status of the button.

cogs/stats/__init__.py

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,24 @@ async def channel_stats(
8686
# NOTE: Shortcut accessors are placed at the top of the function so that the exceptions they raise are displayed before any further errors may be sent
8787
main_guild: discord.Guild = self.bot.main_guild
8888

89-
channel_id: int = ctx.channel_id
89+
match ctx.channel:
90+
case None:
91+
CTX_CHANNEL_IS_NONE_MESSAGE: Final[str] = (
92+
"Cannot send stats graph when `ctx.channel` is `None`."
93+
)
94+
raise TypeError(CTX_CHANNEL_IS_NONE_MESSAGE)
95+
case discord.ForumChannel() | discord.CategoryChannel():
96+
await self.command_send_error(
97+
ctx,
98+
message=(
99+
f"The `/{ctx.command}` command cannot be used in the channel: {
100+
ctx.channel.mention
101+
}"
102+
),
103+
)
104+
return
105+
106+
channel_id: int | None = ctx.channel_id
90107

91108
if str_channel_id:
92109
if not re.fullmatch(r"\A\d{17,20}\Z", str_channel_id):
@@ -97,6 +114,12 @@ async def channel_stats(
97114

98115
channel_id = int(str_channel_id)
99116

117+
if channel_id is None:
118+
CTX_CHANNEL_ID_IS_NONE_MESSAGE: Final[str] = (
119+
"Cannot produce stats graph when `ctx.channel_id` is `None`."
120+
)
121+
raise TypeError(CTX_CHANNEL_ID_IS_NONE_MESSAGE)
122+
100123
channel: discord.TextChannel | None = discord.utils.get(
101124
main_guild.text_channels, id=channel_id
102125
)
@@ -157,6 +180,23 @@ async def server_stats(self, ctx: "TeXBotApplicationContext") -> None:
157180
main_guild: discord.Guild = self.bot.main_guild
158181
guest_role: discord.Role = await self.bot.guest_role
159182

183+
match ctx.channel:
184+
case None:
185+
CTX_CHANNEL_IS_NONE_MESSAGE: Final[str] = (
186+
"Cannot send stats graph when `ctx.channel` is `None`."
187+
)
188+
raise TypeError(CTX_CHANNEL_IS_NONE_MESSAGE)
189+
case discord.ForumChannel() | discord.CategoryChannel():
190+
await self.command_send_error(
191+
ctx,
192+
message=(
193+
f"The `/{ctx.command}` command cannot be used in the channel: {
194+
ctx.channel.mention
195+
}"
196+
),
197+
)
198+
return
199+
160200
await ctx.defer(ephemeral=True)
161201

162202
message_counts: Mapping[str, Mapping[str, int]] = await get_server_message_counts(
@@ -248,6 +288,23 @@ async def user_stats(self, ctx: "TeXBotApplicationContext") -> None:
248288
)
249289
return
250290

291+
match ctx.channel:
292+
case None:
293+
CTX_CHANNEL_IS_NONE_MESSAGE: Final[str] = (
294+
"Cannot send stats graph when `ctx.channel` is `None`."
295+
)
296+
raise TypeError(CTX_CHANNEL_IS_NONE_MESSAGE)
297+
case discord.ForumChannel() | discord.CategoryChannel():
298+
await self.command_send_error(
299+
ctx,
300+
message=(
301+
f"The `/{ctx.command}` command cannot be used in the channel: {
302+
ctx.channel.mention
303+
}"
304+
),
305+
)
306+
return
307+
251308
await ctx.defer(ephemeral=True)
252309

253310
message_counts: dict[str, int] = {"Total": 0}
@@ -314,6 +371,23 @@ async def left_member_stats(self, ctx: "TeXBotApplicationContext") -> None:
314371
# NOTE: Shortcut accessors are placed at the top of the function so that the exceptions they raise are displayed before any further errors may be sent
315372
main_guild: discord.Guild = self.bot.main_guild
316373

374+
match ctx.channel:
375+
case None:
376+
CTX_CHANNEL_IS_NONE_MESSAGE: Final[str] = (
377+
"Cannot send stats graph when `ctx.channel` is `None`."
378+
)
379+
raise TypeError(CTX_CHANNEL_IS_NONE_MESSAGE)
380+
case discord.ForumChannel() | discord.CategoryChannel():
381+
await self.command_send_error(
382+
ctx,
383+
message=(
384+
f"The `/{ctx.command}` command cannot be used in the channel: {
385+
ctx.channel.mention
386+
}"
387+
),
388+
)
389+
return
390+
317391
await ctx.defer(ephemeral=True)
318392

319393
left_member_counts: dict[str, int] = {

0 commit comments

Comments
 (0)