pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

`repr()` of some classes doesn't use subclass name

Open aatle opened this issue 6 months ago • 4 comments

Environment:

pygame.print_debug_info()
pygame-ce 2.5.0 (SDL 2.30.3, Python 3.12.4)
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:

In some classes such as Surface, Rect, Vector2, and others, the repr() behavior uses a hard-coded class name string instead of a dynamic access of the class name. Subclass instances and normal instances appear the same with repr(). Example with Vector2 subclass:

>>> repr(MyPosition(0.1, 0.2))
'Vector2(0.1, 0.2)'

Expected behavior:

The repr() should include the name of the actual instance class instead of the class that implemented the functionality.

>>> repr(MyPosition(0.1, 0.2))
'MyPosition(0.1, 0.2)'

Test code

import pygame as pg

class S(pg.Surface):
  __slots__ = ()

print(S([1,1]))

class R(pg.Rect):
  __slots__ = ()

print(R(0,0,5,5))

class V(pg.Vector2):
  __slots__ = ()

print(repr(V(1.2, 1.3)))

Side note: I think the Surface repr should also say when it has per-pixel alpha.

aatle avatar Aug 07 '24 22:08 aatle