Skip to content

Commit 5a513a1

Browse files
committed
Remove sentinel-value dependency
I did not like this how this library doesn't use pickle singletons I'll use classes for now since those can switch to something better later
1 parent eb7c4e8 commit 5a513a1

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Removed dependency on `sentinel-value`.
13+
1014
## [5.4.2] - 2025-11-28
1115

1216
### Removed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ requires-python = ">=3.10"
2121
dependencies = [
2222
"attrs >=23.1.0",
2323
"cattrs >=23.1.2",
24-
"sentinel-value >=1.0.0",
2524
"typing-extensions >=4.13.1",
2625
]
2726

tcod/ecs/constants.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22

33
from __future__ import annotations
44

5-
from typing import Final
65

7-
from sentinel_value import sentinel
6+
class _IgnoreSetState(type):
7+
def __setstate__(cls, _state: object) -> None:
8+
"""Ignore setstate on outdated sentinel-value pickle data."""
89

9-
IsA: Final = sentinel("IsA")
10-
"""The default is-a relationship tag used for entity inheritance."""
10+
11+
class IsA(metaclass=_IgnoreSetState):
12+
"""The default is-a relationship tag used for entity inheritance."""
13+
14+
def __new__(cls: type[IsA], *_args: object) -> type[IsA]: # type: ignore[misc]
15+
"""Return own type instead of instance, for outdated sentinel-value pickle data."""
16+
return cls
17+
18+
19+
_sentinel_IsA = IsA # Compatibility with sentinel-value, deprecated since 5.4 # noqa: N816

tests/test_ecs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,10 @@ def test_type_form() -> None:
301301
world[None].components[TupleKey] = (1, 2)
302302
x, y = world[None].components[TupleKey]
303303
assert (x, y) == (1, 2)
304+
305+
306+
PICKLED_ISA = b"\x80\x03ctcod.ecs.constants\n_sentinel_IsA\nq\x00X\x12\x00\x00\x00tcod.ecs.constantsq\x01X\x03\x00\x00\x00IsAq\x02\x86q\x03\x81q\x04}q\x05(X\r\x00\x00\x00instance_nameq\x06h\x02X\x0b\x00\x00\x00module_nameq\x07h\x01X\x0e\x00\x00\x00qualified_nameq\x08X\x16\x00\x00\x00tcod.ecs.constants.IsAq\tub." # cspell: disable-line
307+
308+
309+
def test_unpickle_is_a() -> None:
310+
assert pickle.loads(PICKLED_ISA) is tcod.ecs.IsA # noqa: S301

0 commit comments

Comments
 (0)