Skip to content

Commit 175e201

Browse files
committed
Undocument and deprecate redundant sprite group classes
To clean up the sprite documentation I've removed three classes that do nothing. I've also removed OrderedUpdates from the code, it became effectively redundant after we dropped Python 3.5 support and all dictionaries became ordered. Ordered dictionaries were then made part of the Python specification in version 3.7 which is currently our lowest supported version.
1 parent 4fc37dd commit 175e201

File tree

2 files changed

+29
-57
lines changed

2 files changed

+29
-57
lines changed

docs/reST/ref/sprite.rst

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ Sprites are not thread safe. So lock them yourself if using threads.
203203
204204
A simple container for Sprite objects. This class can be inherited to create
205205
containers with more specific behaviors. The constructor takes any number of
206-
Sprite arguments to add to the Group. The group supports the following
206+
Sprite arguments to add to the Group. All sprites in groups are stored in the
207+
order they were added to the group. The group supports the following
207208
standard Python operations:
208209

209210
::
@@ -297,8 +298,7 @@ Sprites are not thread safe. So lock them yourself if using threads.
297298
``Sprite.image`` attribute for the source surface, and ``Sprite.rect``
298299
for the position.
299300

300-
The Group does not keep sprites in any order, so the draw order is
301-
arbitrary.
301+
The Group keeps sprites in the order they were added, they will be drawn in this order.
302302

303303
.. ## Group.draw ##
304304
@@ -337,22 +337,6 @@ Sprites are not thread safe. So lock them yourself if using threads.
337337
338338
.. ## pygame.sprite.Group ##
339339
340-
.. class:: RenderPlain
341-
342-
| :sl:`Same as pygame.sprite.Group`
343-
344-
This class is an alias to ``pygame.sprite.Group()``. It has no additional functionality.
345-
346-
.. ## pygame.sprite.RenderClear ##
347-
348-
.. class:: RenderClear
349-
350-
| :sl:`Same as pygame.sprite.Group`
351-
352-
This class is an alias to ``pygame.sprite.Group()``. It has no additional functionality.
353-
354-
.. ## pygame.sprite.RenderClear ##
355-
356340
.. class:: RenderUpdates
357341

358342
| :sl:`Group sub-class that tracks dirty updates.`
@@ -380,18 +364,6 @@ Sprites are not thread safe. So lock them yourself if using threads.
380364
381365
.. ## pygame.sprite.RenderUpdates ##
382366
383-
.. function:: OrderedUpdates
384-
385-
| :sl:`RenderUpdates sub-class that draws Sprites in order of addition.`
386-
| :sg:`OrderedUpdates(*sprites) -> OrderedUpdates`
387-
388-
This class derives from ``pygame.sprite.RenderUpdates()``. It maintains the
389-
order in which the Sprites were added to the Group for rendering. This makes
390-
adding and removing Sprites from the Group a little slower than regular
391-
Groups.
392-
393-
.. ## pygame.sprite.OrderedUpdates ##
394-
395367
.. class:: LayeredUpdates
396368

397369
| :sl:`LayeredUpdates is a sprite group that handles layers and draws like OrderedUpdates.`

src_py/sprite.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,24 @@ def __init__(self, *sprites):
655655
self.add(*sprites)
656656

657657

658-
RenderPlain = Group
659-
RenderClear = Group
658+
class RenderPlain(Group):
659+
def __init__(self, *sprites):
660+
super().__init__(*sprites)
661+
warn(
662+
"This class will be removed in version 2.4.0",
663+
DeprecationWarning,
664+
stacklevel=2,
665+
)
666+
667+
668+
class RenderClear(Group):
669+
def __init__(self, *sprites):
670+
super().__init__(*sprites)
671+
warn(
672+
"This class will be removed in version 2.4.0",
673+
DeprecationWarning,
674+
stacklevel=2,
675+
)
660676

661677

662678
class RenderUpdates(Group):
@@ -690,31 +706,15 @@ def draw(self, surface):
690706

691707

692708
class OrderedUpdates(RenderUpdates):
693-
"""RenderUpdates class that draws Sprites in order of addition
694-
695-
pygame.sprite.OrderedUpdates(*sprites): return OrderedUpdates
696-
697-
This class derives from pygame.sprite.RenderUpdates(). It maintains
698-
the order in which the Sprites were added to the Group for rendering.
699-
This makes adding and removing Sprites from the Group a little
700-
slower than regular Groups.
701-
702-
"""
703-
704709
def __init__(self, *sprites):
705-
self._spritelist = []
706-
RenderUpdates.__init__(self, *sprites)
707-
708-
def sprites(self):
709-
return self._spritelist.copy()
710-
711-
def add_internal(self, sprite, layer=None):
712-
RenderUpdates.add_internal(self, sprite)
713-
self._spritelist.append(sprite)
714-
715-
def remove_internal(self, sprite):
716-
RenderUpdates.remove_internal(self, sprite)
717-
self._spritelist.remove(sprite)
710+
super().__init__(*sprites)
711+
warn(
712+
"OrderedUpdates is now just an alias to RenderUpdates, order of "
713+
"sprites is now maintained in all sprite Group classes. This "
714+
"class will be removed in version 2.4.0",
715+
DeprecationWarning,
716+
stacklevel=2,
717+
)
718718

719719

720720
class LayeredUpdates(AbstractGroup):

0 commit comments

Comments
 (0)