Skip to content

Commit b454524

Browse files
committed
Deprecate EventDispatch class
This class has faded into irrelevance due to modern Python language features. I need to discourage its usage in new programs.
1 parent c7b6bc5 commit b454524

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
1919
- `Console.print_box` has been replaced by `Console.print`.
2020
- `Console.draw_frame`: deprecated `clear`, `fg`, `bg`, and `bg_blend` being given as positional arguments.
2121
- `Console.draw_rect`: deprecated `fg`, `bg`, and `bg_blend` being given as positional arguments.
22+
- The `EventDispatch` class is now deprecated.
23+
This class was made before Python supported protocols and structural pattern matching,
24+
now the class serves little purpose and its usage can create a minor technical burden.
2225

2326
## [17.1.0] - 2025-03-29
2427

tcod/event.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
from typing import TYPE_CHECKING, Any, Callable, Final, Generic, Iterator, Mapping, NamedTuple, TypeVar
8888

8989
import numpy as np
90-
from typing_extensions import Literal
90+
from typing_extensions import Literal, deprecated
9191

9292
import tcod.event
9393
import tcod.event_constants
@@ -1238,6 +1238,10 @@ def wait(timeout: float | None = None) -> Iterator[Any]:
12381238
return get()
12391239

12401240

1241+
@deprecated(
1242+
"Event dispatch should be handled via a single custom method in a Protocol instead of this class.",
1243+
category=DeprecationWarning,
1244+
)
12411245
class EventDispatch(Generic[T]):
12421246
'''Dispatches events to methods depending on the events type attribute.
12431247
@@ -1248,6 +1252,10 @@ class EventDispatch(Generic[T]):
12481252
This is now a generic class.
12491253
The type hints at the return value of :any:`dispatch` and the `ev_*` methods.
12501254
1255+
.. deprecated:: Unreleased
1256+
Event dispatch should be handled via a single custom method in a Protocol instead of this class.
1257+
Note that events can and should be handled using Python's `match` statement.
1258+
12511259
Example::
12521260
12531261
import tcod

0 commit comments

Comments
 (0)