Open
Description
Environment:
Platform: Windows-11-10.0.22631-SP0
System: Windows
System Version: 10.0.22631
Processor: Intel64 Family 6 Model 167 Stepping 1, GenuineIntel
Architecture: Bits: 64bit Linkage: WindowsPE
Python: CPython 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]
pygame version: 2.5.0
SDL versions: Linked: 2.30.3 Compiled: 2.30.3
SDL Mixer versions: Linked: 2.8.0 Compiled: 2.8.0
SDL Font versions: Linked: 2.22.0 Compiled: 2.22.0
SDL Image versions: Linked: 2.8.2 Compiled: 2.8.2
Freetype versions: Linked: 2.11.1 Compiled: 2.11.1
Display Driver: Display Not Initialized
Mixer Driver: Mixer Not Initialized
Current behavior:
According to the documentation, pygame.sprite.Group.has()
(and __contains__
) will return True if all given sprites are contained in the group, False otherwise.
However, for the edge case of no sprites given (or equivalently, empty iterable), this method incorrectly returns False
. This is probably what was intended, but is wrong.
In has()
method:
Lines 521 to 522 in cdc2756
Expected behavior:
The has()
method should return True
if no sprites (no arguments, empty group, etc.) are given. This is similar to the built-in all()
function.
The technical term is "vacuous truth". If you need more explanation, ask me.
Steps to reproduce:
import pygame
group = pygame.sprite.Group()
print('has():', group.has(), group.has([]), group.has(group))