Skip to content
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

Add Python 3.12 support #1357

Merged
merged 18 commits into from
Nov 18, 2023
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/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.8, 3.9, "3.10", 3.11]
python-version: [3.8, 3.9, "3.10", 3.11, 3.12]

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gateway APIs.
Built on good intentions and the hope that it will be extendable and reusable, rather than an obstacle for future
development.

Python 3.8, 3.9, 3.10 and 3.11 are currently supported.
Python 3.8, 3.9, 3.10, 3.11 and 3.12 are currently supported.

## Installation

Expand Down
1 change: 1 addition & 0 deletions changes/1357.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Python 3.12 support.
3 changes: 2 additions & 1 deletion hikari/impl/shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ def _handle_other_message(self, message: aiohttp.WSMessage, /) -> typing.NoRetur
close_code = int(message.data)

can_reconnect = close_code < 4000 or close_code in _RECONNECTABLE_CLOSE_CODES
raise errors.GatewayServerClosedConnectionError(message.extra, close_code, can_reconnect)
# str(message.extra) is used to cast the possible None to a string
raise errors.GatewayServerClosedConnectionError(str(message.extra), close_code, can_reconnect)

if message.type == aiohttp.WSMsgType.CLOSING or message.type == aiohttp.WSMsgType.CLOSED:
# May be caused by the server shutting us down.
Expand Down
2 changes: 1 addition & 1 deletion hikari/internal/fast_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from typing_extensions import Self

_Protocol: FastProtocolChecking = NotImplemented
_IGNORED_ATTRS = typing.EXCLUDED_ATTRIBUTES + ["__qualname__", "__slots__"]
_IGNORED_ATTRS = frozenset(typing.EXCLUDED_ATTRIBUTES) | {"__qualname__", "__slots__"}


def _check_if_ignored(name: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp~=3.8
aiohttp~=3.9
attrs~=23.1
colorlog~=6.7
multidict~=6.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def parse_requirements_file(path):
maintainer_email=metadata.email,
license=metadata.license,
url=metadata.url,
python_requires=">=3.8.0,<3.12",
python_requires=">=3.8.0,<3.13",
packages=setuptools.find_namespace_packages(include=["hikari*"]),
entry_points={"console_scripts": ["hikari = hikari.cli:main"]},
install_requires=parse_requirements_file("requirements.txt"),
Expand Down Expand Up @@ -95,6 +95,7 @@ def parse_requirements_file(path):
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Communications :: Chat",
"Topic :: Internet :: WWW/HTTP",
Expand Down
8 changes: 6 additions & 2 deletions tests/hikari/impl/test_event_manager_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ async def test_handle_dispatch_ignores_cancelled_errors(self, event_manager, eve

@pytest.mark.asyncio()
async def test_handle_dispatch_handles_exceptions(self, event_manager, event_loop):
mock_task = mock.Mock()
# On Python 3.12+ Asyncio uses this to get the task's context if set to call the
# error handler in. We want to avoid for this test for simplicity.
mock_task.get_context.return_value = None
event_manager._enabled_for_consumer = mock.Mock(return_value=True)
exc = Exception("aaaa!")
consumer = mock.Mock(callback=mock.AsyncMock(side_effect=exc))
Expand All @@ -580,12 +584,12 @@ async def test_handle_dispatch_handles_exceptions(self, event_manager, event_loo
shard = object()
pl = {"i like": "cats"}

with mock.patch.object(asyncio, "current_task") as current_task:
with mock.patch.object(asyncio, "current_task", return_value=mock_task):
await event_manager._handle_dispatch(consumer, shard, pl)

error_handler.assert_called_once_with(
event_loop,
{"exception": exc, "message": "Exception occurred in raw event dispatch conduit", "task": current_task()},
{"exception": exc, "message": "Exception occurred in raw event dispatch conduit", "task": mock_task},
)

@pytest.mark.asyncio()
Expand Down