Skip to content

Commit 7a559b9

Browse files
committed
Update deprecations to use PEP 702
1 parent 08b2b21 commit 7a559b9

File tree

6 files changed

+29
-33
lines changed

6 files changed

+29
-33
lines changed

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+
- Updated deprecations to use [PEP 702](https://peps.python.org/pep-0702/).
13+
1014
## [5.3.0] - 2025-03-08
1115

1216
### Added

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies = [
2222
"attrs >=23.1.0",
2323
"cattrs >=23.1.2",
2424
"sentinel-value >=1.0.0",
25-
"typing-extensions >=4.4.0",
25+
"typing-extensions >=4.9.0",
2626
]
2727

2828
[tool.setuptools_scm]

tcod/ecs/entity.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import warnings
65
from typing import (
76
TYPE_CHECKING,
87
Any,
@@ -23,7 +22,7 @@
2322

2423
import attrs
2524
from sentinel_value import sentinel
26-
from typing_extensions import Self
25+
from typing_extensions import Self, deprecated
2726

2827
import tcod.ecs.callbacks
2928
import tcod.ecs.query
@@ -74,14 +73,13 @@ class Entity:
7473
"""This entities unique identifier."""
7574

7675
@property
76+
@deprecated("Use '.registry' instead of '.world'")
7777
def world(self) -> Registry:
7878
"""Deprecated alias for registry.
7979
8080
.. deprecated:: 5.1
8181
Use :any:`registry` instead.
8282
"""
83-
if __debug__:
84-
warnings.warn("Use '.registry' instead of '.world'", DeprecationWarning, stacklevel=2)
8583
return self.registry
8684

8785
def __new__(cls, registry: Registry, uid: object = object) -> Entity: # noqa: PYI034
@@ -284,13 +282,13 @@ def relation_tag(self) -> EntityRelationsExclusive:
284282
return EntityRelationsExclusive(self, (IsA,))
285283

286284
@property
285+
@deprecated("The '.relation_tags' attribute has been renamed to '.relation_tag'", category=FutureWarning)
287286
def relation_tags(self) -> EntityRelationsExclusive:
288287
"""Access an entities exclusive relations.
289288
290289
.. deprecated:: 3.2
291290
This attribute was renamed to :any:`relation_tag`.
292291
"""
293-
warnings.warn("The '.relation_tags' attribute has been renamed to '.relation_tag'", FutureWarning, stacklevel=2)
294292
return EntityRelationsExclusive(self, (IsA,))
295293

296294
@property
@@ -303,12 +301,8 @@ def relation_tags_many(self) -> EntityRelations:
303301
"""
304302
return EntityRelations(self, (IsA,))
305303

306-
def _set_name(self, value: object, stacklevel: int = 1) -> None:
307-
warnings.warn(
308-
"The name feature has been deprecated and will be removed.",
309-
FutureWarning,
310-
stacklevel=stacklevel + 1,
311-
)
304+
@deprecated("The name feature has been deprecated and will be removed.", category=FutureWarning)
305+
def _set_name(self, value: object) -> None:
312306
old_name = self.name
313307
if old_name is not None: # Remove self from names
314308
del self.registry._names_by_name[old_name]
@@ -333,8 +327,9 @@ def name(self) -> object:
333327
return self.registry._names_by_entity.get(self)
334328

335329
@name.setter
330+
@deprecated("The name feature has been deprecated and will be removed.", category=FutureWarning)
336331
def name(self, value: object) -> None:
337-
self._set_name(value, stacklevel=2)
332+
self._set_name(value)
338333

339334
def __repr__(self) -> str:
340335
"""Return a representation of this entity.
@@ -410,17 +405,13 @@ def __call__(self, *, traverse: Iterable[object]) -> Self:
410405
"""
411406
return self.__class__(self.entity, tuple(traverse))
412407

413-
def set(self, value: object, *, _stacklevel: int = 1) -> None:
408+
@deprecated("Setting values without an explicit key has been deprecated.", category=FutureWarning)
409+
def set(self, value: object) -> None:
414410
"""Assign or overwrite a component, automatically deriving the key.
415411
416412
.. deprecated:: 3.1
417413
Setting values without an explicit key has been deprecated.
418414
"""
419-
warnings.warn(
420-
"Setting values without an explicit key has been deprecated.",
421-
FutureWarning,
422-
stacklevel=_stacklevel + 1,
423-
)
424415
key = value.__class__
425416
self[key] = value
426417

@@ -498,15 +489,17 @@ def __len__(self) -> int:
498489
"""Return the number of components belonging to this entity."""
499490
return len(self.keys())
500491

501-
def update_values(self, values: Iterable[object], *, _stacklevel: int = 1) -> None:
492+
@deprecated("Setting values without an explicit key has been deprecated.", category=FutureWarning)
493+
def update_values(self, values: Iterable[object]) -> None:
502494
"""Add or overwrite multiple components inplace, deriving the keys from the values.
503495
504496
.. deprecated:: 3.1
505497
Setting values without an explicit key has been deprecated.
506498
"""
507499
for value in values:
508-
self.set(value, _stacklevel=_stacklevel + 1)
500+
self.set(value)
509501

502+
@deprecated("This method has been deprecated. Iterate over items instead.", category=FutureWarning)
510503
def by_name_type(self, name_type: type[_T1], component_type: type[_T2]) -> Iterator[tuple[_T1, type[_T2]]]:
511504
"""Iterate over all of an entities component keys with a specific (name_type, component_type) combination.
512505
@@ -515,7 +508,6 @@ def by_name_type(self, name_type: type[_T1], component_type: type[_T2]) -> Itera
515508
.. deprecated:: 3.1
516509
This method has been deprecated. Iterate over items instead.
517510
"""
518-
warnings.warn("This method has been deprecated. Iterate over items instead.", FutureWarning, stacklevel=2)
519511
# Naive implementation until I feel like optimizing it
520512
for key in self:
521513
if not isinstance(key, tuple):

tcod/ecs/query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from weakref import WeakKeyDictionary, WeakSet
1010

1111
import attrs
12-
from typing_extensions import Self
12+
from typing_extensions import Self, deprecated
1313

1414
import tcod.ecs.entity
1515
from tcod.ecs.constants import IsA
@@ -333,14 +333,13 @@ class BoundQuery:
333333
_query: _Query = attrs.field(factory=_QueryLogicalAnd)
334334

335335
@property
336+
@deprecated("Use '.registry' instead of '.world'")
336337
def world(self) -> Registry:
337338
"""Deprecated alias for registry.
338339
339340
.. deprecated:: 5.1
340341
Use :any:`registry` instead.
341342
"""
342-
if __debug__:
343-
warnings.warn("Use '.registry' instead of '.world'", DeprecationWarning, stacklevel=2)
344343
return self.registry
345344

346345
def get_entities(self) -> AbstractSet[Entity]:

tcod/ecs/registry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import TYPE_CHECKING, Any, DefaultDict, Dict, Final, Iterable, Mapping, NoReturn, Set, TypeVar
88

99
import attrs
10+
from typing_extensions import deprecated
1011

1112
import tcod.ecs._converter
1213
import tcod.ecs.query
@@ -151,6 +152,10 @@ class Registry:
151152
"""
152153

153154
@property
155+
@deprecated(
156+
"The 'registry.global_' attribute has been deprecated. Use 'registry[None]' to access this entity.",
157+
category=FutureWarning,
158+
)
154159
def global_(self) -> Entity:
155160
"""A unique globally accessible entity.
156161
@@ -168,11 +173,6 @@ def global_(self) -> Entity:
168173
>>> registry[None].components[("turn", int)]
169174
0
170175
"""
171-
warnings.warn(
172-
"The 'registry.global_' attribute has been deprecated. Use 'registry[None]' to access this entity.",
173-
FutureWarning,
174-
stacklevel=2,
175-
)
176176
return Entity(self, None)
177177

178178
def __setstate__(self, state: dict[str, Any]) -> None:
@@ -300,12 +300,12 @@ def new_entity(
300300
if isinstance(components, Mapping):
301301
entity.components.update(components)
302302
elif components:
303-
entity.components.update_values(components, _stacklevel=2)
303+
entity.components.update_values(components)
304304
entity_tags = entity.tags
305305
for tag in tags:
306306
entity_tags.add(tag)
307307
if name is not None:
308-
entity._set_name(name, stacklevel=2)
308+
entity._set_name(name)
309309
return entity
310310

311311
@property

tests/test_traversal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ def test_inherited_clear() -> None:
212212
world["A"].components[int] = 1
213213
world["A"].tags.add("foo")
214214
world["A"].relation_components[str][world["B"]] = "bar"
215-
world["A"].relation_tags["baz"] = world["B"]
215+
with pytest.warns():
216+
world["A"].relation_tags["baz"] = world["B"]
216217
child = world["A"].instantiate()
217218
child.clear() # Could hang if broken
218219
x = child.components

0 commit comments

Comments
 (0)