Skip to content

Commit 9913c43

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 Typing-extensions can be used for `_raise` because that doesn't need to support pickle
1 parent eb7c4e8 commit 9913c43

5 files changed

Lines changed: 27 additions & 9 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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ requires-python = ">=3.10"
2121
dependencies = [
2222
"attrs >=23.1.0",
2323
"cattrs >=23.1.2",
24-
"sentinel-value >=1.0.0",
25-
"typing-extensions >=4.13.1",
24+
"typing-extensions >=4.14.0",
2625
]
2726

2827
[tool.setuptools_scm]

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

tcod/ecs/entity.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
from weakref import WeakKeyDictionary, WeakValueDictionary
1515

1616
import attrs
17-
from sentinel_value import sentinel
18-
from typing_extensions import Self, TypeForm, deprecated
17+
from typing_extensions import Self, Sentinel, TypeForm, deprecated
1918

2019
import tcod.ecs.callbacks
2120
import tcod.ecs.query
@@ -34,7 +33,7 @@
3433
_T1 = TypeVar("_T1")
3534
_T2 = TypeVar("_T2")
3635

37-
_raise: Final = sentinel("_raise")
36+
_raise: Final = Sentinel("_raise")
3837

3938
_entity_table: WeakKeyDictionary[Registry, WeakValueDictionary[object, Entity]] = WeakKeyDictionary()
4039
"""A weak table of registries and unique identifiers to entity objects.

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)