I'm having a really strange problem with Python super() and inheritance and properties. First, the code:
#!/usr/bin/env python3
import pyglet
import pygame
class Sprite(pyglet.sprite.Sprite):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.rect = pygame.Rect(0, 0, self.width, self.height)
self.rect.center = self.x, self.y
@property
def x(self):
return super().x
@x.setter
def x(self, value):
super(Sprite, self.__class__).x.fset(self, value)
self.rect.centerx = value
@property
def y(self):
return super().y
@y.setter
def y(self, value):
super(Sprite, self.__class__).y.fset(self, value)
self.rect.centery = value
This works fine. However, what I want (what seems Pythonic to me)
#super(Sprite, self.__class__).x.fset(self, value)
super().x = value
doesn't work even though
super().x
gets the value fine. x in this case is a property of the superclass with both fset and fget defined. So why doesn't it work?