Investigate using dict.__missing__ to avoid having objc.super

Issue #154 closed
Ronald Oussoren
repo owner created an issue

PyObjC has its own implementation of the super object to work around limitations in the default super (see also the stalled PEP 447).

It might be possible to replace the class dictionary of Objective-C proxy classes by a dict subclass with an __missing__ method that does the PyObjC magic. If that works this could also simplify the __getattribute__ of those classes (that method currently reimplements the object.__getattribute__ with some small tweaks.

Comments (5)

  1. Ronald Oussoren reporter

    The main problem with this is that there will have to be link back from the dict to the class or meta-class which introduces a cycle that might not be expected. OTOH, removing ObjC classes is not possible anyway.

    Dealing with a subclass of dict seems to be manageable, although this obviously relies on implementation details of CPython (see #147).

    I've started hacking on this during an EP2016 lunch, but haven't gotten far enough yet to even compile the new code, let alone check if this is a viable avenue.

    P.S. Another reason to look into this is that this will make PEP 447 support easier, that would remove most of the code for this hack but would use the same integration points with the rest of PyObjC.

  2. Ronald Oussoren reporter

    A quick experiment shows that this doesn't work, and code inspection of PyDict_GetItem shows why this doesn't work: PyDict_GetItem contains no reference to __missing__ and hence will never call this method.

    In hindsight this is obvious, PyDict_GetItem is basically the __getitem__ implementation for exactly the dict type and that type doesn't have __missing__.

  3. Log in to comment