Subclass of NSObject, super has no attribute init

Issue #110 closed
Justin Nesselrotte
created an issue

If you define a class, that's a subclass of NSObject...

>>> class MyClass(NSObject):
...     def init(self):
...             self = super(MyClass, self).init()
...             return self

... and try to initialize it....

>>> test = MyClass.alloc().init()

... It will give the following error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in init AttributeError: 'super' object has no attribute 'init'

I'm not sure if it's an error with my syntax or not, but this seems to indicate it's not:

Comments (5)

  1. Ronald Oussoren repo owner

    That's correct: builtin.super doesn't work correctly with Cocoa classes, use objc.super instead. I do that by adding "from objc import super" to the top of files that use super in Cocoa classes.

    The reason this is needed is that builtin.super makes assumptions about classes that aren't true for PyObjC's proxies for Cocoa classes. That already caused sporadic errors in PyObjC 2.x, and is a lot more problematic in PyObjC 3.x due to changes in the way the PyObjC class proxy is initialized.

  2. Ronald Oussoren repo owner

    Not a bug in PyObjC.

    BTW. I have created a PEP to fix super, but haven't had enough time to get that accepted by the core devs (that is, the PEP text isn't clear enough yet to make it my proposal and its implications clear to someone that hasn't recently read the source code of CPython's method resolution machinery)

  3. Log in to comment