Skip to content

Commit beffd5b

Browse files
committed
Avoid deprecated code within Context.convert_event
Promote mouse attribute deprecations to decorators
1 parent 01a810c commit beffd5b

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org/) since version
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- Silenced internal deprecation warning within `Context.convert_event`.
12+
913
## [19.3.0] - 2025-07-26
1014

1115
Thanks to cr0ne for pointing out missing texture scaling options.

tcod/event.py

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -418,39 +418,38 @@ def __init__(
418418
self.state = state
419419

420420
@property
421+
@deprecated("The mouse.pixel attribute is deprecated. Use mouse.position instead.")
421422
def pixel(self) -> Point:
422-
warnings.warn(
423-
"The mouse.pixel attribute is deprecated. Use mouse.position instead.",
424-
DeprecationWarning,
425-
stacklevel=2,
426-
)
427423
return self.position
428424

429425
@pixel.setter
430426
def pixel(self, value: Point) -> None:
431427
self.position = value
432428

433429
@property
430+
@deprecated(
431+
"The mouse.tile attribute is deprecated."
432+
" Use mouse.position of the event returned by context.convert_event instead."
433+
)
434434
def tile(self) -> Point:
435-
warnings.warn(
436-
"The mouse.tile attribute is deprecated. Use mouse.position of the event returned by context.convert_event instead.",
437-
DeprecationWarning,
438-
stacklevel=2,
439-
)
440435
return _verify_tile_coordinates(self._tile)
441436

442437
@tile.setter
438+
@deprecated(
439+
"The mouse.tile attribute is deprecated."
440+
" Use mouse.position of the event returned by context.convert_event instead."
441+
)
443442
def tile(self, xy: tuple[float, float]) -> None:
444443
self._tile = Point(*xy)
445444

446445
def __repr__(self) -> str:
447-
return f"tcod.event.{self.__class__.__name__}(position={tuple(self.position)!r}, tile={tuple(self.tile)!r}, state={MouseButtonMask(self.state)})"
446+
return f"tcod.event.{self.__class__.__name__}(position={tuple(self.position)!r}, tile={tuple(self._tile or (0, 0))!r}, state={MouseButtonMask(self.state)})"
448447

449448
def __str__(self) -> str:
450449
return ("<%s, position=(x=%i, y=%i), tile=(x=%i, y=%i), state=%s>") % (
451450
super().__str__().strip("<>"),
452451
*self.position,
453-
*self.tile,
452+
*(self._tile or (0, 0)),
454453
MouseButtonMask(self.state),
455454
)
456455

@@ -492,41 +491,29 @@ def __init__(
492491
self._tile_motion = Point(*tile_motion) if tile_motion is not None else None
493492

494493
@property
494+
@deprecated("The mouse.pixel_motion attribute is deprecated. Use mouse.motion instead.")
495495
def pixel_motion(self) -> Point:
496-
warnings.warn(
497-
"The mouse.pixel_motion attribute is deprecated. Use mouse.motion instead.",
498-
DeprecationWarning,
499-
stacklevel=2,
500-
)
501496
return self.motion
502497

503498
@pixel_motion.setter
499+
@deprecated("The mouse.pixel_motion attribute is deprecated. Use mouse.motion instead.")
504500
def pixel_motion(self, value: Point) -> None:
505-
warnings.warn(
506-
"The mouse.pixel_motion attribute is deprecated. Use mouse.motion instead.",
507-
DeprecationWarning,
508-
stacklevel=2,
509-
)
510501
self.motion = value
511502

512503
@property
504+
@deprecated(
505+
"The mouse.tile_motion attribute is deprecated."
506+
" Use mouse.motion of the event returned by context.convert_event instead."
507+
)
513508
def tile_motion(self) -> Point:
514-
warnings.warn(
515-
"The mouse.tile_motion attribute is deprecated."
516-
" Use mouse.motion of the event returned by context.convert_event instead.",
517-
DeprecationWarning,
518-
stacklevel=2,
519-
)
520509
return _verify_tile_coordinates(self._tile_motion)
521510

522511
@tile_motion.setter
512+
@deprecated(
513+
"The mouse.tile_motion attribute is deprecated."
514+
" Use mouse.motion of the event returned by context.convert_event instead."
515+
)
523516
def tile_motion(self, xy: tuple[float, float]) -> None:
524-
warnings.warn(
525-
"The mouse.tile_motion attribute is deprecated."
526-
" Use mouse.motion of the event returned by context.convert_event instead.",
527-
DeprecationWarning,
528-
stacklevel=2,
529-
)
530517
self._tile_motion = Point(*xy)
531518

532519
@classmethod

0 commit comments

Comments
 (0)