diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 96e654a8..38e13042 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,8 +3,8 @@ repos: rev: 23.9.1 hooks: - id: black - args: [--target-version, py311, --preview] - language_version: python3.11 + args: [--target-version, py312, --preview] + language_version: python3.12 - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: @@ -13,7 +13,7 @@ repos: rev: "v0.0.292" hooks: - id: ruff - language_version: python3.11 + language_version: python3.12 - repo: https://github.com/Lucas-C/pre-commit-hooks rev: v1.5.4 hooks: diff --git a/Dockerfile b/Dockerfile index 87b44798..488cb1f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM python:3.11-alpine +FROM python:3.12-alpine -RUN apk add --no-cache gcc bash +RUN apk add --no-cache gcc bash musl-dev WORKDIR /app diff --git a/common/fuzzy.py b/common/fuzzy.py index cda0eddd..d5fd3295 100644 --- a/common/fuzzy.py +++ b/common/fuzzy.py @@ -19,10 +19,10 @@ import rapidfuzz from rapidfuzz import process -T = typing.TypeVar("T") - -def extract_from_list( +def extract_from_list[ + T +]( argument: str, list_of_items: typing.Collection[T], processors: typing.Iterable[typing.Callable], diff --git a/common/playerlist_events.py b/common/playerlist_events.py index 1a764c02..26be0bc6 100644 --- a/common/playerlist_events.py +++ b/common/playerlist_events.py @@ -23,8 +23,6 @@ import common.models as models import common.playerlist_utils as pl_utils -_C = typing.TypeVar("_C") - @typing.dataclass_transform( eq_default=False, @@ -32,7 +30,7 @@ kw_only_default=False, field_specifiers=(attrs.field,), ) -def define() -> typing.Callable[[_C], _C]: +def define[C]() -> typing.Callable[[C], C]: return attrs.define(eq=False, order=False, hash=False, kw_only=False) # type: ignore diff --git a/common/splash_texts.py b/common/splash_texts.py index 50095f42..1add0dc3 100644 --- a/common/splash_texts.py +++ b/common/splash_texts.py @@ -16,6 +16,7 @@ import asyncio import datetime +import platform import random import typing @@ -32,8 +33,12 @@ class SplashTextUpdated(ipy.events.BaseEvent): pass +# https://docs.python.org/3/library/platform.html?highlight=platform#platform.python_version_tuple +PYTHON_VERSION = platform.python_version_tuple() + + # please add new entries to the end of the list -splash_texts = ( +splash_texts: tuple[str, ...] = ( "/online is used more than /playerlist", "99% bug free!", "Monkeypatch free!", # for now @@ -72,7 +77,7 @@ class SplashTextUpdated(ipy.events.BaseEvent): "PURPOSELY_INVALID_KEY_AAAAAAAAAAAAAAAA", # actually used in the bot "Watching players on Realms!", "Do bots dream of electric sheep?", - "Python 3.11!", + f"{platform.python_implementation()} {PYTHON_VERSION[0]}.{PYTHON_VERSION[1]}!", # ie CPython 3.12 "Now in purple!", "Keyboard compatible!", "Made by AstreaTSS!", diff --git a/exts/premium.py b/exts/premium.py index 6fa33747..f844b913 100644 --- a/exts/premium.py +++ b/exts/premium.py @@ -30,10 +30,10 @@ import common.premium_code as premium_code import common.utils as utils -CommandT = typing.TypeVar("CommandT", ipy.BaseCommand, ipy.const.AsyncCallable) - -def premium_check() -> typing.Callable[[CommandT], CommandT]: +def premium_check[ + T: (ipy.BaseCommand, ipy.const.AsyncCallable) +]() -> typing.Callable[[T], T]: async def check(ctx: utils.RealmContext) -> bool: config = await ctx.fetch_config() diff --git a/exts/statistics.py b/exts/statistics.py index dcbb0ce0..b5b85936 100644 --- a/exts/statistics.py +++ b/exts/statistics.py @@ -33,10 +33,8 @@ import common.stats_utils as stats_utils import common.utils as utils -AsyncCallableT = typing.TypeVar("AsyncCallableT", bound=ipy.const.AsyncCallable) - -def amazing_modal_error_handler(func: AsyncCallableT) -> AsyncCallableT: +def amazing_modal_error_handler[T: ipy.const.AsyncCallable](func: T) -> T: async def wrapper( self: typing.Any, unknown: ipy.events.ModalCompletion | ipy.ModalContext, diff --git a/main.py b/main.py index b6e0a164..f188e278 100644 --- a/main.py +++ b/main.py @@ -491,13 +491,12 @@ async def start() -> None: if __name__ == "__main__": - loop_factory = None + run_method = asyncio.run # use uvloop if possible with contextlib.suppress(ImportError): import uvloop # type: ignore - loop_factory = uvloop.new_event_loop + run_method = uvloop.run - with asyncio.Runner(loop_factory=loop_factory) as runner: - runner.run(start()) + run_method(start()) diff --git a/pyproject.toml b/pyproject.toml index 77abab33..2befcb0e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,13 +66,10 @@ per-file-ignores = {} # Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -target-version = "py311" +target-version = "py312" fix = true [tool.ruff.mccabe] # Unlike Flake8, default to a complexity level of 10. max-complexity = 10 - -[tool.ruff.isort] -extra-standard-library = ["tomllib"] diff --git a/requirements.txt b/requirements.txt index ea999296..63095fa4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +aiohttp==3.9.0b0 discord-py-interactions[speedup]==5.10.0 tansy==0.8.0 humanize==4.8.0