Skip to content

Commit b40f085

Browse files
committed
fix new mypy issues
1 parent 48cf464 commit b40f085

9 files changed

Lines changed: 3715 additions & 26 deletions

File tree

commands/utility/schedulemessage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def schedule_message(
6363
if (
6464
commandInfo.guild is not None
6565
and repeat
66-
and isinstance(commandInfo.user, discord.Member)
66+
and isinstance(commandInfo.user, discord.Member) # type: ignore[redundant-expr]
6767
and isinstance(commandInfo.channel, discord.abc.GuildChannel)
6868
and not commandInfo.channel.permissions_for(commandInfo.user).manage_messages
6969
):
@@ -110,7 +110,7 @@ async def schedule_message(
110110

111111
else:
112112
dmChannel = await commandInfo.user.create_dm()
113-
if not dmChannel:
113+
if dmChannel is None:
114114
embed = utility.tanjunEmbed(
115115
title=tanjunLocalizer.localize(
116116
commandInfo.locale,
@@ -140,7 +140,7 @@ async def schedule_message(
140140
if (
141141
channel
142142
and commandInfo.guild is not None
143-
and isinstance(commandInfo.user, discord.Member)
143+
and isinstance(commandInfo.user, discord.Member) # type: ignore[redundant-expr]
144144
and isinstance(commandInfo.channel, discord.abc.GuildChannel)
145145
and not commandInfo.channel.permissions_for(commandInfo.user).manage_messages
146146
):

commands/utility/setupBoosterChannel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def setupBoosterChannel(commandInfo: commandInfo, category: discord.Catego
2121
await commandInfo.reply(embed=embed)
2222
return
2323

24-
if isinstance(commandInfo.user, discord.Member) and not commandInfo.user.guild_permissions.administrator:
24+
if not getattr(commandInfo.user, "guild_permissions", None) or not commandInfo.user.guild_permissions.administrator: # type: ignore[union-attr]
2525
embed = utility.tanjunEmbed(
2626
title=tanjunLocalizer.localize(
2727
commandInfo.locale,

commands/utility/setupBoosterRole.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def setupBoosterRole(commandInfo: commandInfo, role: discord.Role) -> None
2121
await commandInfo.reply(embed=embed)
2222
return
2323

24-
if isinstance(commandInfo.user, discord.Member) and not commandInfo.user.guild_permissions.administrator:
24+
if not getattr(commandInfo.user, "guild_permissions", None) or not commandInfo.user.guild_permissions.administrator: # type: ignore[union-attr]
2525
embed = utility.tanjunEmbed(
2626
title=tanjunLocalizer.localize(
2727
commandInfo.locale,

localizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def load_translations(self, locale: str) -> list[dict[str, object]]:
2020
except FileNotFoundError:
2121
try:
2222
with open("locales/en.json", encoding="utf-8") as file:
23-
data: object = json.load(file)
24-
return cast(list[dict[str, object]], data)
23+
fallback_data: object = json.load(file)
24+
return cast(list[dict[str, object]], fallback_data)
2525
except (FileNotFoundError, json.JSONDecodeError):
2626
return []
2727
except json.JSONDecodeError:
@@ -31,7 +31,7 @@ def load_translations(self, locale: str) -> list[dict[str, object]]:
3131
def get_translation(self, translations: list[dict[str, object]], key: str) -> dict[str, object] | None:
3232
"""Retrieve a nested translation using dot notation for nested keys."""
3333
translation: dict[str, object] | None = next(
34-
(t for t in translations if isinstance(t, dict) and str(t.get("identifier", "")).lower() == key.lower()),
34+
(t for t in translations if str(t.get("identifier", "")).lower() == key.lower()),
3535
None,
3636
)
3737

minigames/addLevelXp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from localizer import tanjunLocalizer
2323
from utility import get_level_for_xp # , checkIfHasPro
2424

25-
notifiedUsers = []
25+
notifiedUsers: list[int] = []
2626

2727

2828
async def addLevelXp(message: discord.Message) -> None:

minigames/wordchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async def wordchain(message: discord.Message) -> None:
4646
await message.delete()
4747
return
4848

49-
if await get_wordchain_last_user_id(message.channel.id) == message.author.id:
49+
if str(await get_wordchain_last_user_id(message.channel.id)) == str(message.author.id):
5050
await message.delete()
5151
return
5252

mypy_reports.txt

Lines changed: 3688 additions & 0 deletions
Large diffs are not rendered by default.

translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def translate(
2626
self,
2727
string: app_commands.locale_str,
2828
locale: discord.Locale,
29-
context: app_commands.TranslationContext,
29+
context: app_commands.TranslationContext[Any, Any], # type: ignore[type-arg]
3030
) -> str | None:
3131
if str(locale.value) not in ["de", "de-DE", "en", "en-US", "en-GB"]:
3232
return None

utility.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def __init__(
182182
self.timestamp = timestamp
183183

184184
@classmethod
185-
def from_dict(cls, data: Mapping[str, Any]) -> Self:
185+
def from_dict(cls, data: "Mapping[str, Any]") -> "tanjunEmbed":
186186
self = cls.__new__(cls)
187187

188188
self.title = None
@@ -276,11 +276,11 @@ def __eq__(self, other: object) -> bool:
276276
return self.to_dict() == other.to_dict()
277277

278278
@property
279-
def colour(self) -> discord.Colour | None:
279+
def colour(self) -> discord.Colour | None: # type: ignore[override]
280280
return getattr(self, "_colour", None)
281281

282282
@colour.setter
283-
def colour(self, value: int | discord.Colour | None) -> None:
283+
def colour(self, value: int | discord.Colour | None) -> None: # type: ignore[override]
284284
if value is None:
285285
self._colour = None
286286
elif isinstance(value, discord.Colour):
@@ -289,11 +289,11 @@ def colour(self, value: int | discord.Colour | None) -> None:
289289
self._colour = discord.Colour(value=value)
290290

291291
@property
292-
def color(self) -> discord.Colour | None:
292+
def color(self) -> discord.Colour | None: # type: ignore[override]
293293
return self.colour
294294

295295
@color.setter
296-
def color(self, value: int | discord.Colour | None) -> None:
296+
def color(self, value: int | discord.Colour | None) -> None: # type: ignore[override]
297297
self.colour = value
298298

299299
@property
@@ -416,7 +416,7 @@ def set_field_at(self, index: int, *, name: object, value: object, inline: bool
416416
raise IndexError("field index out of range")
417417
return self
418418

419-
def to_dict(self) -> dict[str, Any]:
419+
def to_dict(self) -> dict[str, Any]: # type: ignore[override]
420420
result: dict[str, object] = {}
421421
for key in self.__slots__:
422422
if key.startswith("_") and hasattr(self, key):
@@ -826,7 +826,7 @@ def eval_(node: ast.AST, variables: VariablesType) -> float | int | complex:
826826
raise TypeError(f"'{func_id_str}' is not a callable function.")
827827
args = [eval_(arg, variables) for arg in node.args]
828828
try:
829-
return func_to_call(*args)
829+
return cast(float | int | complex, func_to_call(*args))
830830
except TypeError as e:
831831
raise TypeError(f"Error calling function '{getattr(func_to_call, '__name__', func_id_str)}': {e}")
832832
elif isinstance(node, ast.Name):
@@ -858,14 +858,15 @@ def get_xp_for_level(level: int, scaling: str, custom_formula: str | None = None
858858
print(f"Warning: Unknown XP scaling '{scaling}'. Using 'medium'.")
859859
result = LEVEL_SCALINGS["medium"](level)
860860

861-
if isinstance(result, complex):
861+
if type(result) is complex: # type: ignore[redundant-expr]
862862
print(f"Warning: Custom XP formula resulted in a complex number ({result}). Using real part or 0.")
863863
return math.floor(result.real) if result.real is not None else 0
864864
elif isinstance(result, (float, int)):
865865
if math.isinf(result) or math.isnan(result):
866866
print(f"Warning: XP calculation resulted in {result}. Returning 0.")
867867
return 0
868868
return math.floor(result)
869+
return 0
869870

870871

871872
def get_level_for_xp(xp: int, scaling: str, custom_formula: str | None = None) -> int:
@@ -1057,11 +1058,11 @@ def __init__(
10571058

10581059
@property
10591060
def guild(self) -> discord.Guild | None:
1060-
return self._mock_guild
1061+
return cast(discord.Guild | None, self._mock_guild)
10611062

10621063
@property
10631064
def channel(self) -> discord.abc.MessageableChannel | None:
1064-
return self._mock_channel
1065+
return cast(discord.abc.MessageableChannel | None, self._mock_channel)
10651066

10661067
async def original_response(self) -> discord.Message:
10671068
if hasattr(self.response, "message") and self.response.message:
@@ -1112,7 +1113,7 @@ async def send_message(
11121113

11131114
channel = self.interaction._mock_channel
11141115
if channel and hasattr(self.interaction, "_state"):
1115-
self.message = discord.Message(state=self.interaction._state, channel=channel, data=message_data)
1116+
self.message = discord.Message(state=self.interaction._state, channel=cast(Any, channel), data=message_data) # type: ignore[arg-type]
11161117
else:
11171118
self.message = None
11181119
self.interaction._response_issued = True
@@ -1154,7 +1155,7 @@ async def send(
11541155
mock_channel = self._state.Client.get_channel(0)
11551156

11561157
# Use type ignore since we're mocking discord.Message creation
1157-
return discord.Message(state=self._state, channel=mock_channel, data=message_data)
1158+
return discord.Message(state=self._state, channel=cast(Any, mock_channel), data=message_data) # type: ignore[arg-type]
11581159

11591160
async def edit_message(self, message_id: int, **kwargs: Any) -> discord.Message:
11601161
raise NotImplementedError
@@ -1174,10 +1175,10 @@ def create_mock_interaction(bot_instance: InteractionClient) -> MockInteraction:
11741175
A MockInteraction instance
11751176
"""
11761177
# Create mock guild and channel objects that match the protocol
1177-
mock_guild = type("MockGuild", (), {"id": 12345, "name": "Mock Guild"})() if bot_instance is not None else None
1178-
mock_channel = type("MockChannel", (), {"id": 67890})() if bot_instance is not None else None
1178+
mock_guild = type("MockGuild", (), {"id": 12345, "name": "Mock Guild"})()
1179+
mock_channel = type("MockChannel", (), {"id": 67890})()
11791180

1180-
if bot_instance is None or bot_instance.user is None:
1181+
if bot_instance.user is None:
11811182
raise ValueError("Bot instance or bot user is not valid.")
11821183

11831184
# Create a mock user that matches the protocol

0 commit comments

Comments
 (0)