From ef91e1552a2ea8112e73ac91b9ba32c08d9d5fae Mon Sep 17 00:00:00 2001 From: Kyle Benesch <4b796c65+github@gmail.com> Date: Sat, 21 Nov 2026 02:27:25 -0800 Subject: [PATCH] Upgrade to Python 3.12 Drop 3.10 & 3.11 Apply Ruff updates Remove old hacks Update requirements to match current usage: - Just say Python 3, active versions are always supported - Remove libsdl mention, this gets bundled in wheels - Update MacOS to match current wheels --- .github/workflows/python-package.yml | 10 ++--- CHANGELOG.md | 4 ++ README.rst | 5 +-- build_libtcod.py | 4 +- build_sdl.py | 3 +- pyproject.toml | 2 +- scripts/tag_release.py | 2 +- setup.py | 2 +- tcod/_internal.py | 10 ++--- tcod/console.py | 4 +- tcod/context.py | 4 +- tcod/event.py | 57 +++++++++++----------------- tcod/path.py | 3 +- tcod/sdl/_internal.py | 4 +- tcod/sdl/audio.py | 4 +- tcod/sdl/sys.py | 3 +- tcod/sdl/video.py | 4 +- tcod/tileset.py | 4 +- 18 files changed, 56 insertions(+), 73 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index a0894287..b2a8b222 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -109,17 +109,17 @@ jobs: strategy: matrix: os: ["ubuntu-latest", "windows-latest"] - python-version: ["3.10", "3.14t", "pypy-3.10"] + python-version: ["3.12", "3.14t", "pypy-3.12"] architecture: ["x64"] include: - os: "windows-latest" - python-version: "3.10" + python-version: "3.12" architecture: "x86" - os: "windows-latest" python-version: "3.14t" architecture: "x86" - os: "windows-11-arm" - python-version: "3.11" + python-version: "3.12" architecture: "arm64" - os: "windows-11-arm" python-version: "3.14t" @@ -239,7 +239,7 @@ jobs: strategy: matrix: arch: ["x86_64", "aarch64"] - build: ["cp310-manylinux*", "pp311-manylinux*", "cp314t-manylinux*"] + build: ["cp312-manylinux*", "pp312-manylinux*", "cp314t-manylinux*"] env: BUILD_DESC: "" steps: @@ -296,7 +296,7 @@ jobs: strategy: fail-fast: true matrix: - python: ["cp310-*_universal2", "cp314t-*_universal2", "pp311-*"] + python: ["cp312-*_universal2", "cp314t-*_universal2", "pp312-*"] env: PYTHON_DESC: "" steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2421d3c5..7383751e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version ## [Unreleased] +### Removed + +- Dropped support for Python 3.10 & 3.11. + ## [21.2.5] - 2026-11-21 ### Changed diff --git a/README.rst b/README.rst index 32e9164c..586c246f 100755 --- a/README.rst +++ b/README.rst @@ -46,9 +46,8 @@ For the most part it's just:: ============== Requirements ============== -* Python 3.10+ -* Windows, Linux, or MacOS X 10.9+. -* On Linux, requires libsdl3 +* Python 3 +* Windows, Linux, or MacOS X 10.15+. =========== Changelog diff --git a/build_libtcod.py b/build_libtcod.py index 51748b77..91a27e42 100755 --- a/build_libtcod.py +++ b/build_libtcod.py @@ -29,7 +29,7 @@ if TYPE_CHECKING: from collections.abc import Iterable, Iterator -Py_LIMITED_API: int | None = 0x03100000 +Py_LIMITED_API: int | None = 0x03120000 HEADER_PARSE_PATHS = ("tcod/", "libtcod/src/libtcod/") HEADER_PARSE_EXCLUDES = ("gl2_ext_.h", "renderer_gl_internal.h", "event.h") @@ -227,7 +227,7 @@ def walk_sources(directory: str) -> Iterator[str]: for include in includes: try: ffi.cdef(include.header) - except Exception: # noqa: PERF203 + except Exception: # Print the source, for debugging. print(f"Error with: {include.path}") for i, line in enumerate(include.header.split("\n"), 1): diff --git a/build_sdl.py b/build_sdl.py index 09dc9188..cd112675 100755 --- a/build_sdl.py +++ b/build_sdl.py @@ -168,8 +168,7 @@ def check_sdl_version() -> None: ) raise RuntimeError(msg) from exc except subprocess.CalledProcessError as exc: - if sys.version_info >= (3, 11): - exc.add_note(f"Note: {os.environ.get('PKG_CONFIG_PATH')=}") + exc.add_note(f"Note: {os.environ.get('PKG_CONFIG_PATH')=}") raise logger.info(f"Found SDL {sdl_version_str}.") sdl_version = tuple(int(s) for s in sdl_version_str.split(".")) diff --git a/pyproject.toml b/pyproject.toml index bde13b74..c26984ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ dynamic = ["version"] description = "The official Python port of libtcod." authors = [{ name = "Kyle Benesch", email = "4b796c65+tcod@gmail.com" }] readme = "README.rst" -requires-python = ">=3.10" +requires-python = ">=3.12" license = "BSD-2-Clause" license-files = [ "LICENSE.txt", diff --git a/scripts/tag_release.py b/scripts/tag_release.py index 5f39e4b2..a46bdd02 100755 --- a/scripts/tag_release.py +++ b/scripts/tag_release.py @@ -36,7 +36,7 @@ def parse_changelog(args: argparse.Namespace) -> tuple[str, str]: assert match header, changes, tail = match.groups() - iso_date = datetime.datetime.now(tz=datetime.timezone.utc).date().isoformat() + iso_date = datetime.datetime.now(tz=datetime.UTC).date().isoformat() tagged = f"\n## [{args.tag}] - {iso_date}\n{changes}" if args.verbose: print("--- Tagged section:") diff --git a/setup.py b/setup.py index 3ff98114..3b61569d 100755 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ def get_package_data() -> list[str]: options = { "bdist_wheel": { - "py_limited_api": "cp310", + "py_limited_api": "cp312", } } if "free-threading build" in sys.version: diff --git a/tcod/_internal.py b/tcod/_internal.py index b67242b8..27ef717f 100644 --- a/tcod/_internal.py +++ b/tcod/_internal.py @@ -19,7 +19,6 @@ FuncType = Callable[..., Any] F = TypeVar("F", bound=FuncType) -T = TypeVar("T") def _deprecate_passthrough( @@ -61,7 +60,7 @@ def _check(error: int) -> int: return error -def _check_p(pointer: T) -> T: +def _check_p[T](pointer: T) -> T: """Treats NULL pointers as errors and raises a libtcod exception.""" if not pointer: _raise_tcod_error() @@ -94,13 +93,13 @@ def _int(int_or_str: SupportsInt | str | bytes) -> int: return int(int_or_str) -def _bytes(string: AnyStr) -> bytes: +def _bytes(string: AnyStr) -> bytes: # noqa: UP047 if isinstance(string, str): return string.encode("utf-8") return string -def _unicode(string: AnyStr, stacklevel: int = 2) -> str: +def _unicode(string: AnyStr, stacklevel: int = 2) -> str: # noqa: UP047 if isinstance(string, bytes): warnings.warn( "Passing byte strings as parameters to Unicode functions is deprecated.", @@ -129,8 +128,7 @@ def _path_encode(path: Path) -> bytes: try: return str(path).encode(locale.getlocale()[1] or "utf-8") # Stay classy, Windows except UnicodeEncodeError as exc: - if sys.version_info >= (3, 11): - exc.add_note("""Consider calling 'locale.setlocale(locale.LC_CTYPES, ".UTF8")' to support Unicode paths.""") + exc.add_note("""Consider calling 'locale.setlocale(locale.LC_CTYPES, ".UTF8")' to support Unicode paths.""") raise diff --git a/tcod/console.py b/tcod/console.py index bfcbce00..2ff56200 100644 --- a/tcod/console.py +++ b/tcod/console.py @@ -9,10 +9,10 @@ import warnings from pathlib import Path -from typing import TYPE_CHECKING, Any, Literal, overload +from typing import TYPE_CHECKING, Any, Literal, Self, overload import numpy as np -from typing_extensions import Self, deprecated +from typing_extensions import deprecated import tcod._internal import tcod.constants diff --git a/tcod/context.py b/tcod/context.py index 01ed61f7..5e02ac43 100644 --- a/tcod/context.py +++ b/tcod/context.py @@ -31,9 +31,9 @@ import warnings from math import floor from pathlib import Path -from typing import TYPE_CHECKING, Any, Literal, NoReturn, TypeVar +from typing import TYPE_CHECKING, Any, Literal, NoReturn, Self, TypeVar -from typing_extensions import Self, deprecated +from typing_extensions import deprecated import tcod.console import tcod.event diff --git a/tcod/event.py b/tcod/event.py index e206ccd1..ab2e20f0 100644 --- a/tcod/event.py +++ b/tcod/event.py @@ -93,20 +93,18 @@ TYPE_CHECKING, Any, Final, - Generic, Literal, NamedTuple, Protocol, - TypeAlias, + Self, TypedDict, - TypeVar, overload, runtime_checkable, ) import attrs import numpy as np -from typing_extensions import Self, deprecated +from typing_extensions import deprecated import tcod.context import tcod.event_constants @@ -120,10 +118,7 @@ if TYPE_CHECKING: from numpy.typing import NDArray -T = TypeVar("T") -_EventType = TypeVar("_EventType", bound="Event") - -_C_SDL_Event: TypeAlias = Any +type _C_SDL_Event = Any """A CFFI pointer to an SDL_Event union. See SDL docs: https://wiki.libsdl.org/SDL3/SDL_Event @@ -173,27 +168,20 @@ def _pixel_to_tile(xy: tuple[float, float], /) -> Point[float] | None: return Point(float(xy_out[0]), float(xy_out[1])) -if sys.version_info >= (3, 11) or TYPE_CHECKING: - - class Point(NamedTuple, Generic[T]): - """A 2D position used for events with mouse coordinates. +class Point[T](NamedTuple): + """A 2D position used for events with mouse coordinates. - .. seealso:: - :any:`MouseMotion` :any:`MouseButtonDown` :any:`MouseButtonUp` - - .. versionchanged:: 19.0 - Now uses floating point coordinates due to the port to SDL3. - """ + .. seealso:: + :any:`MouseMotion` :any:`MouseButtonDown` :any:`MouseButtonUp` - x: T - """A pixel or tile coordinate starting with zero as the left-most position.""" - y: T - """A pixel or tile coordinate starting with zero as the top-most position.""" -else: + .. versionchanged:: 19.0 + Now uses floating point coordinates due to the port to SDL3. + """ - class Point(NamedTuple): # noqa: D101 - x: Any - y: Any + x: T + """A pixel or tile coordinate starting with zero as the left-most position.""" + y: T + """A pixel or tile coordinate starting with zero as the top-most position.""" def _verify_tile_coordinates(xy: Point[int] | None) -> Point[int]: @@ -1429,7 +1417,7 @@ def wait(timeout: float | None = None) -> Iterator[Event]: Event dispatching should be handled via a single custom method in a Protocol instead of this class.""", category=DeprecationWarning, ) -class EventDispatch(Generic[T]): +class EventDispatch[T]: '''Dispatches events to methods depending on the events type attribute. To use this class, make a sub-class and override the relevant `ev_*` methods. @@ -1741,13 +1729,13 @@ def get_mouse_state() -> MouseState: @overload -def convert_coordinates_from_window( - event: _EventType, +def convert_coordinates_from_window[EventType: Event]( + event: EventType, /, context: tcod.context.Context | tcod.sdl.render.Renderer, console: tcod.console.Console | tuple[int, int], dest_rect: tuple[int, int, int, int] | None = None, -) -> _EventType: ... +) -> EventType: ... @overload def convert_coordinates_from_window( xy: tuple[float, float], @@ -1756,13 +1744,13 @@ def convert_coordinates_from_window( console: tcod.console.Console | tuple[int, int], dest_rect: tuple[int, int, int, int] | None = None, ) -> tuple[float, float]: ... -def convert_coordinates_from_window( - event: _EventType | tuple[float, float], +def convert_coordinates_from_window[EventType: Event]( + event: EventType | tuple[float, float], /, context: tcod.context.Context | tcod.sdl.render.Renderer, console: tcod.console.Console | tuple[int, int], dest_rect: tuple[int, int, int, int] | None = None, -) -> _EventType | tuple[float, float]: +) -> EventType | tuple[float, float]: """Return an event or position with window mouse coordinates converted into console tile coordinates. Args: @@ -1819,11 +1807,10 @@ def _sdl_event_watcher(userdata: Any, sdl_event: _C_SDL_Event) -> int: # noqa: return 0 -_EventCallback = TypeVar("_EventCallback", bound=Callable[[Event], None]) _event_watch_handles: dict[Callable[[Event], None], Any] = {} # Callbacks and their FFI handles. -def add_watch(callback: _EventCallback) -> _EventCallback: +def add_watch[EventCallback: Callable[[Event], None]](callback: EventCallback) -> EventCallback: """Add a callback for watching events. This function can be called with the callback to register, or be used as a decorator. diff --git a/tcod/path.py b/tcod/path.py index 29307921..67f44dd0 100644 --- a/tcod/path.py +++ b/tcod/path.py @@ -21,10 +21,9 @@ import functools import itertools import warnings -from typing import TYPE_CHECKING, Any, Final, Literal +from typing import TYPE_CHECKING, Any, Final, Literal, Self import numpy as np -from typing_extensions import Self import tcod.map from tcod._internal import _check diff --git a/tcod/sdl/_internal.py b/tcod/sdl/_internal.py index db67fa2e..50d7bc62 100644 --- a/tcod/sdl/_internal.py +++ b/tcod/sdl/_internal.py @@ -5,9 +5,7 @@ import logging import sys from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, NoReturn, Protocol, TypeVar, overload, runtime_checkable - -from typing_extensions import Self +from typing import TYPE_CHECKING, Any, NoReturn, Protocol, Self, TypeVar, overload, runtime_checkable from tcod.cffi import ffi, lib diff --git a/tcod/sdl/audio.py b/tcod/sdl/audio.py index 28cfac45..fa91bcda 100644 --- a/tcod/sdl/audio.py +++ b/tcod/sdl/audio.py @@ -44,10 +44,10 @@ import threading import weakref from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Final, Literal, NamedTuple +from typing import TYPE_CHECKING, Any, Final, Literal, NamedTuple, Self import numpy as np -from typing_extensions import Self, deprecated +from typing_extensions import deprecated import tcod.sdl.sys from tcod.cffi import ffi, lib diff --git a/tcod/sdl/sys.py b/tcod/sdl/sys.py index c4056c69..3c5273ec 100644 --- a/tcod/sdl/sys.py +++ b/tcod/sdl/sys.py @@ -2,8 +2,7 @@ import enum import warnings - -from typing_extensions import Self +from typing import Self from tcod.cffi import ffi, lib from tcod.sdl._internal import _check, _get_error diff --git a/tcod/sdl/video.py b/tcod/sdl/video.py index e9565f88..29a61a25 100644 --- a/tcod/sdl/video.py +++ b/tcod/sdl/video.py @@ -11,10 +11,10 @@ import enum import sys -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, Self import numpy as np -from typing_extensions import Self, deprecated +from typing_extensions import deprecated import tcod.sdl.constants from tcod.cffi import ffi, lib diff --git a/tcod/tileset.py b/tcod/tileset.py index 58ddf058..c5d17f14 100644 --- a/tcod/tileset.py +++ b/tcod/tileset.py @@ -17,10 +17,10 @@ import itertools from collections.abc import Iterator, Mapping, MutableMapping from pathlib import Path -from typing import TYPE_CHECKING, Any, SupportsInt, overload +from typing import TYPE_CHECKING, Any, Self, SupportsInt, overload import numpy as np -from typing_extensions import Self, deprecated +from typing_extensions import deprecated from tcod._internal import _check, _check_p, _console, _path_encode, _raise_tcod_error from tcod.cffi import ffi, lib