Skip to content

Commit 7e14b31

Browse files
committed
Update tcod.sdl.render equality functions and add missing docs.
1 parent a3901f4 commit 7e14b31

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tcod/sdl/render.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class Texture:
149149
"""
150150

151151
def __init__(self, sdl_texture_p: Any, sdl_renderer_p: Any = None) -> None:
152+
"""Encapsulate an SDL_Texture pointer. This function is private."""
152153
self.p = sdl_texture_p
153154
self._sdl_renderer_p = sdl_renderer_p # Keep alive.
154155
query = self._query()
@@ -165,8 +166,11 @@ def __init__(self, sdl_texture_p: Any, sdl_renderer_p: Any = None) -> None:
165166
self.height: Final[int] = query[3]
166167
"""Texture pixel height, read only."""
167168

168-
def __eq__(self, other: Any) -> bool:
169-
return bool(self.p == getattr(other, "p", None))
169+
def __eq__(self, other: object) -> bool:
170+
"""Return True if compared to the same texture."""
171+
if isinstance(other, Texture):
172+
return bool(self.p == other.p)
173+
return NotImplemented
170174

171175
def _query(self) -> tuple[int, int, int, int]:
172176
"""Return (format, access, width, height)."""
@@ -243,6 +247,7 @@ class Renderer:
243247
"""SDL Renderer."""
244248

245249
def __init__(self, sdl_renderer_p: Any) -> None:
250+
"""Encapsulate an SDL_Renderer pointer. This function is private."""
246251
if ffi.typeof(sdl_renderer_p) is not ffi.typeof("struct SDL_Renderer*"):
247252
msg = f"Expected a {ffi.typeof('struct SDL_Window*')} type (was {ffi.typeof(sdl_renderer_p)})."
248253
raise TypeError(msg)
@@ -251,8 +256,11 @@ def __init__(self, sdl_renderer_p: Any) -> None:
251256
raise TypeError(msg)
252257
self.p = sdl_renderer_p
253258

254-
def __eq__(self, other: Any) -> bool:
255-
return bool(self.p == getattr(other, "p", None))
259+
def __eq__(self, other: object) -> bool:
260+
"""Return True if compared to the same renderer."""
261+
if isinstance(other, Renderer):
262+
return bool(self.p == other.p)
263+
return NotImplemented
256264

257265
def copy(
258266
self,

0 commit comments

Comments
 (0)