jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

super() seems to be broken #196

Closed villares closed 6 years ago

villares commented 6 years ago

I have written a small test example...

def setup():
    a = A(5)
    a.plot()
    b = B(10)
    b.plot()

class A():
    def __init__(self, psize):
        self.s = psize
        self.x, self.y = random(width), random(height)

    def plot(self):
        ellipse(self.x, self.y, self.s, self.s)

class B(A):
    def __init__(self, psize):
        super().__init__(psize)
        # TypeError:super() takes 1-2 arguments (0 given)
        # A.__init__(self, psize) # will work fine...
        self.c = color(random(256))
jdf commented 6 years ago

It looks like you're trying to use Python 3's super (and old-style classes). Here's a working version of your program:

def setup():
    a = A(5)
    a.plot()
    b = B(10)
    b.plot()

class A(object):

    def __init__(self, psize):
        self.s = psize
        self.x, self.y = random(width), random(height)

    def plot(self):
        ellipse(self.x, self.y, self.s, self.s)

class B(A):

    def __init__(self, psize):
        super(B, self).__init__(psize)
        # TypeError:super() takes 1-2 arguments (0 given)
        # A.__init__(self, psize) # will work fine...
        self.c = color(random(256))

Note class A(object): instead of class A(), and note the correct invocation of super.

villares commented 6 years ago

Thanks!!!

On Sun, Oct 29, 2017, 23:54 Jonathan Feinberg notifications@github.com wrote:

Closed #196 https://github.com/jdf/Processing.py-Bugs/issues/196.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jdf/Processing.py-Bugs/issues/196#event-1315849388, or mute the thread https://github.com/notifications/unsubscribe-auth/ADhgDM7NPBpU4w-j086eGrugF42x3Gubks5sxSw3gaJpZM4QKkO0 .