Skip to content

More breaking changes for 11.0 #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python_version: ["3.10", "3.11"]
python_version: ["3.11", "3.12"]

name: Run Linting & Test Suites
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
Changelog
=========

- :breaking:`208` Split ``fakeredis`` optional dependency from the ``async-rediscache`` extra. You can now install with ``[fakeredis]`` to just install fakeredis (with lua support), ``[async-rediscache]`` to install just ``async-rediscache``, or use either ``[all]`` or ``[async-rediscache,fakeredis]`` to install both. This allows users who do no rely on fakeredis to install in 3.12 environments.
- :support:`208` Add support for Python 3.12. Be aware, at time of writing, our usage of fakeredis does not currently support 3.12. This is due to :literal-url:`this lupa issue<https://github.com/scoder/lupa/issues/245>`. Lupa is required by async-rediscache for lua script support within fakeredis. As such, fakeredis can not be installed in a Python 3.12 environment.
- :breaking:`208` Drop support for Python 3.10
- :breaking:`208` Drop support for Pydantic 1.X
- :breaking:`207` Enable more ruff linting rules. See :literal-url:`GitHub release notes <https://github.com/python-discord/bot-core/releases/tag/v11.0.0>` for breaking changes.
- :support:`208` Bump ruff to 0.3.0 and target Python 3.11 now that 3.10 isn't supported.
- :support:`206` Bump ruff from 0.1.15 to 0.2.2, using the new lint config namespace, and linting with the new rules.
- :support:`204` Document the instance attributes of :obj:`pydis_core.BotBase`.

Expand Down
26 changes: 5 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pydis_core/utils/_monkey_patches.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Contains all common monkey patches, used to alter discord to fit our needs."""

import logging
from datetime import datetime, timedelta, timezone
from datetime import UTC, datetime, timedelta
from functools import partial, partialmethod

from discord import Forbidden, http
Expand Down Expand Up @@ -50,13 +50,13 @@ def _patch_typing() -> None:

async def honeybadger_type(self: http.HTTPClient, channel_id: int) -> None:
nonlocal last_403
if last_403 and (datetime.now(tz=timezone.utc) - last_403) < timedelta(minutes=5):
if last_403 and (datetime.now(tz=UTC) - last_403) < timedelta(minutes=5):
log.warning("Not sending typing event, we got a 403 less than 5 minutes ago.")
return
try:
await original(self, channel_id)
except Forbidden:
last_403 = datetime.now(tz=timezone.utc)
last_403 = datetime.now(tz=UTC)
log.warning("Got a 403 from typing event!")

http.HTTPClient.send_typing = honeybadger_type
Expand Down
6 changes: 2 additions & 4 deletions pydis_core/utils/cooldown.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
_HashableArgsTuple = tuple[Hashable, ...]

if typing.TYPE_CHECKING:
import typing_extensions

from pydis_core import BotBase

P = typing.ParamSpec("P")
Expand Down Expand Up @@ -75,15 +73,15 @@ class _SeparatedArguments:
non_hashable: _ArgsList

@classmethod
def from_full_arguments(cls, call_arguments: Iterable[object]) -> typing_extensions.Self:
def from_full_arguments(cls, call_arguments: Iterable[object]) -> typing.Self:
"""Create a new instance from full call arguments."""
hashable = list[Hashable]()
non_hashable = list[object]()

for item in call_arguments:
try:
hash(item)
except TypeError: # noqa: PERF203
except TypeError:
non_hashable.append(item)
else:
hashable.append(item)
Expand Down
5 changes: 2 additions & 3 deletions pydis_core/utils/pagination.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
from collections.abc import Sequence
from contextlib import suppress
from functools import partial
Expand Down Expand Up @@ -267,7 +266,7 @@ async def paginate(
for line in lines:
try:
paginator.add_line(line, empty=empty)
except Exception: # noqa: PERF203
except Exception:
log.exception(f"Failed to add line to paginator: '{line}'")
raise # Should propagate
else:
Expand Down Expand Up @@ -336,7 +335,7 @@ async def paginate(
else:
reaction, user = await ctx.bot.wait_for("reaction_add", timeout=timeout, check=check)
log.trace(f"Got reaction: {reaction}")
except asyncio.TimeoutError:
except TimeoutError:
log.debug("Timed out waiting for a reaction")
break # We're done, no reactions for the last 5 minutes

Expand Down
2 changes: 1 addition & 1 deletion pydis_core/utils/paste_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def send_to_paste_service(
payload = {
"expiry": "30days",
"long": "on", # Use a longer URI for the paste.
"files": [file.dict() for file in files] # Use file.model_dump() when we drop support for pydantic 1.X
"files": [file.model_dump() for file in files]
}
for attempt in range(1, FAILED_REQUEST_ATTEMPTS + 1):
try:
Expand Down
4 changes: 2 additions & 2 deletions pydis_core/utils/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import inspect
import typing
from collections import abc
from datetime import datetime, timezone
from datetime import UTC, datetime
from functools import partial

from discord.errors import Forbidden
Expand Down Expand Up @@ -103,7 +103,7 @@ def schedule_at(self, time: datetime, task_id: abc.Hashable, coroutine: abc.Coro
task_id: A unique ID to create the task with.
coroutine: The function to be called.
"""
now_datetime = datetime.now(time.tzinfo) if time.tzinfo else datetime.now(tz=timezone.utc)
now_datetime = datetime.now(time.tzinfo) if time.tzinfo else datetime.now(tz=UTC)
delay = (time - now_datetime).total_seconds()
if delay > 0:
coroutine = self._await_later(delay, task_id, coroutine)
Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ repository = "https://github.com/python-discord/bot-core"
keywords = ["bot", "discord", "discord.py"]

[tool.poetry.dependencies]
python = "3.10.* || 3.11.*"
python = "3.11.* || 3.12.*"

"discord.py" = "~=2.3.2"
async-rediscache = { version = "1.0.0rc2", extras = ["fakeredis"], optional = true }
pydantic = ">=1.7.4,<3.0.0"
async-rediscache = { version = "1.0.0rc2", optional = true }
fakeredis = { version = "~=2.0", extras = ["lua"], optional = true, python = "<3.12" }
pydantic = "~=2.6"
statsd = "~=4.0"
aiodns = "~=3.1"

[tool.poetry.extras]
async-rediscache = ["async-rediscache"]
fakeredis = ["fakeredis"]
all = ["async-rediscache", "fakeredis"]

[tool.poetry.group.dev.dependencies]
taskipy = "1.12.2"
Expand All @@ -46,7 +49,6 @@ pytest-xdist = "3.5.0"
[tool.poetry.group.lint.dependencies]
ruff = "0.3.0"
pre-commit = "3.6.2"
typing-extensions = "4.10.0"

[tool.poetry.group.doc.dependencies]
Sphinx = "7.2.6"
Expand All @@ -57,7 +59,6 @@ six = "1.16.0"
releases = "2.1.1"
sphinx-multiversion = "0.2.4"
docstring-parser = "0.15"
typing-extensions = "4.10.0"
tomli = "2.0.1"

[tool.taskipy.tasks]
Expand All @@ -77,7 +78,7 @@ source_pkgs = ["pydis_core"]
source = ["tests"]

[tool.ruff]
target-version = "py310"
target-version = "py311"
extend-exclude = [".cache"]
output-format = "concise"
line-length = 120
Expand Down