Skip to content

Commit

Permalink
feat💥: upgrade to python 3.12
Browse files Browse the repository at this point in the history
As simple as the title. This also takes advantage of a few 3.12 features.
Fixes #299
  • Loading branch information
AstreaTSS committed Oct 14, 2023
1 parent 6ddfe96 commit fdb0f0c
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions common/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 1 addition & 3 deletions common/playerlist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@
import common.models as models
import common.playerlist_utils as pl_utils

_C = typing.TypeVar("_C")


@typing.dataclass_transform(
eq_default=False,
order_default=False,
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


Expand Down
9 changes: 7 additions & 2 deletions common/splash_texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import asyncio
import datetime
import platform
import random
import typing

Expand All @@ -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
Expand Down Expand Up @@ -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!",
Expand Down
6 changes: 3 additions & 3 deletions exts/premium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 1 addition & 3 deletions exts/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aiohttp==3.9.0b0
discord-py-interactions[speedup]==5.10.0
tansy==0.8.0
humanize==4.8.0
Expand Down

0 comments on commit fdb0f0c

Please sign in to comment.