Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - shantytown

Pages: [1]
1
Python / Re: Question on inheritance
« on: September 22, 2014, 03:49:19 pm »
Best I can tell cython calls __cinit__ of the parent class first before __init__ of the inheriting class.
http://stackoverflow.com/questions/18260095/cant-override-init-of-class-from-cython-extension

In the latest from github __init__ is used instead of __cinit__ so I imagine inheritance should work there.  I can't find exactly when it changed though.
https://github.com/Sonkun/python-sfml

Perfect. That's exactly the answer I was looking for. I did some googling myself but wasn't looking for the right information I guess. Thanks a lot for your help.

2
Python / Question on inheritance
« on: September 21, 2014, 11:02:00 pm »
class MyRectangleShape(sfml.graphics.RectangleShape):
        def __init__(self):
                print('Output: ' + str(self.size))

box = MyRectangleShape()

Code: [Select]
Output: 0.0x, 0.0y
Why is RectangleShape's constructor implicitly called here? self should not have the attribute size without explicitly calling RectangleShape.__init__(). The reason this is significant is because this will cause all kinds of problems with the way I want to expand this class. Python isn't supposed to work that way. The only way I can imagine this would be intentional is if there is some metaprogramming causing it, and I don't know much about that.

Tried in Python 2.7.7 and 3.2.5. Same behavior in both.

Until I understand the problem, I guess I'll just stick to composition.

Pages: [1]