Skip to content

Commit 5660e4b

Browse files
committed
♻️ Refactor type hints and update dependencies in various files
1 parent 1df7744 commit 5660e4b

File tree

9 files changed

+139
-136
lines changed

9 files changed

+139
-136
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
exclude: \.(po|pot|yml|yaml)$
2222
- repo: https://github.com/astral-sh/ruff-pre-commit
2323
# Ruff version.
24-
rev: v0.11.8
24+
rev: v0.12.1
2525
hooks:
2626
# Run the linter.
2727
- id: ruff

pdm.lock

Lines changed: 110 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ authors = [
66
{name = "Paillat-dev", email = "me@paillat.dev"},
77
]
88
dependencies = [
9-
"py-cord @ git+https://github.com/Pycord-Development/pycord.git@refs/pull/2707/head",
109
"aiohttp>=3.9.5",
1110
"pyyaml>=6.0.1",
1211
"python-dotenv>=1.0.1",
@@ -108,7 +107,8 @@ extend-ignore = [
108107
"FBT002",
109108
"PLR2004",
110109
"PLR0913",
111-
"C901"
110+
"C901",
111+
"RUF200"
112112
]
113113

114114
[tool.aerich]

src/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def main() -> None:
1515
await load_and_run_patches()
1616
# we import main here to apply patches before importing as many things we can
1717
# and allow the patches to be applied to later imported modules
18-
from src.start import start
18+
from src.start import start # noqa: PLC0415
1919

2020
await start()
2121

src/extensions/nice_errors/patch.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
async def patch(config: dict[str, Any]) -> None:
1414
sentry_sdk = None
1515
if config.get("sentry", {}).get("dsn"):
16-
import sentry_sdk
17-
from sentry_sdk.integrations.asyncio import AsyncioIntegration
18-
from sentry_sdk.integrations.logging import LoggingIntegration
19-
from sentry_sdk.scrubber import (
16+
import sentry_sdk # noqa: PLC0415
17+
from sentry_sdk.integrations.asyncio import AsyncioIntegration # noqa: PLC0415
18+
from sentry_sdk.integrations.logging import LoggingIntegration # noqa: PLC0415
19+
from sentry_sdk.scrubber import ( # noqa: PLC0415
2020
DEFAULT_DENYLIST,
2121
DEFAULT_PII_DENYLIST,
2222
EventScrubber,
@@ -35,11 +35,11 @@ async def patch(config: dict[str, Any]) -> None:
3535
)
3636
logger.success("Sentry SDK initialized")
3737

38-
from discord.ui import View
38+
from discord.ui import View # noqa: PLC0415
3939

4040
if TYPE_CHECKING:
41-
from discord import Interaction
42-
from discord.ui import Item
41+
from discord import Interaction # noqa: PLC0415
42+
from discord.ui import Item # noqa: PLC0415
4343

4444
async def on_error(
4545
self: View, # noqa: ARG001

src/i18n/utils.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) NiceBots.xyz
22
# SPDX-License-Identifier: MIT
33

4-
from typing import TYPE_CHECKING, TypeVar
4+
from typing import TYPE_CHECKING
55

66
import discord
77
import yaml
@@ -20,11 +20,7 @@
2020
logger = main_logger.getChild("i18n")
2121

2222

23-
T = TypeVar("T")
24-
V = TypeVar("V")
25-
26-
27-
def remove_none(d: dict[T, V]) -> dict[T, V]:
23+
def remove_none[T, V](d: dict[T, V]) -> dict[T, V]:
2824
"""Remove None values from a dictionary.
2925
3026
Args:
@@ -70,18 +66,16 @@ def merge_command_translations(
7066
return result
7167

7268

73-
CommandT = TypeVar(
74-
"CommandT",
75-
discord.ApplicationCommand, # pyright: ignore[reportMissingTypeArgument]
76-
discord.SlashCommand,
77-
discord.SlashCommandGroup,
78-
prefixed.Command, # pyright: ignore[reportMissingTypeArgument]
79-
discord.MessageCommand,
80-
)
81-
82-
83-
def localize_commands( # noqa: PLR0912
84-
commands: list[CommandT],
69+
def localize_commands[ # noqa: PLR0912
70+
T: (
71+
discord.ApplicationCommand, # pyright: ignore[reportMissingTypeArgument]
72+
discord.SlashCommand,
73+
discord.SlashCommandGroup,
74+
prefixed.Command, # pyright: ignore[reportMissingTypeArgument]
75+
discord.MessageCommand,
76+
)
77+
](
78+
commands: list[T],
8579
translations: ExtensionTranslation
8680
| Deg1CommandTranslation
8781
| Deg2CommandTranslation

src/start.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ async def start_bot(bot: custom.Bot, token: str, rest_config: RestConfig, public
5353

5454

5555
async def start_backend(app: Quart, bot: discord.Bot, token: str) -> None:
56-
from hypercorn.asyncio import serve # pyright: ignore [reportUnknownVariableType]
57-
from hypercorn.config import Config
58-
from hypercorn.logging import Logger as HypercornLogger
56+
from hypercorn.asyncio import serve # pyright: ignore [reportUnknownVariableType] # noqa: PLC0415
57+
from hypercorn.config import Config # noqa: PLC0415
58+
from hypercorn.logging import Logger as HypercornLogger # noqa: PLC0415
5959

6060
class CustomLogger(HypercornLogger):
6161
def __init__(
@@ -202,7 +202,7 @@ async def start(run_bot: bool | None = None, run_backend: bool | None = None) ->
202202
logger.critical("No bot token provided in config, exiting...")
203203
return
204204
if config.db.enabled:
205-
from src.database.config import init
205+
from src.database.config import init # noqa: PLC0415
206206

207207
logger.info("Initializing database...")
208208
await init()

src/utils/iterator.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
# SPDX-License-Identifier: MIT
33

44
from collections.abc import Iterator
5-
from typing import TypeVar
65

7-
T = TypeVar("T")
8-
V = TypeVar("V")
96

10-
11-
def next_default(iterator: Iterator[T], default: V = None) -> T | V:
7+
def next_default[T, V](iterator: Iterator[T], default: V = None) -> T | V:
128
try:
139
return next(iterator)
1410
except StopIteration:

tests/config_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) NiceBots.xyz
22
# SPDX-License-Identifier: MIT
33

4-
# ruff: noqa: S101, S105
4+
# ruff: noqa: S105
55

66
import os
77
from typing import Any

0 commit comments

Comments
 (0)