super method does not work

Issue #118 invalid
Anton Morozov
created an issue

I am using pyobjc 3.0.4 and python version 2.7.9

I have tried the simple example MyClass given below

Fo some reason I am getting the following exception: 'super' object has no attribute 'init'

This seems wrong. Am I doing something incorrectly?

>>> from Foundation import NSObject
>>> class MyClass(NSObject):
...   def init(self):
...     self = super(MyClass, self).init()
...     return self
... 
>>> c = MyClass.alloc().init()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in init
AttributeError: 'super' object has no attribute 'init'
>>> NSObject.alloc().init()
<NSObject: 0x102854b20>

Comments (2)

  1. Ronald Oussoren repo owner

    Use "from objc import super" at the top of the file to get a working version of super.

    This was already necessary in PyObjC 2.x to avoid strange behavior in edge cases and is now always necessary due to implementation changes in PyObjC.

    I have written PEP 447 to add the necessary flexibility to Python's builtin super, but that PEP is stagnant because it deals with a very technical details of Python's attribute resolution process and I haven't been able to describe the problem and my proposal clearly enough to get much traction.

  2. Log in to comment