[PyQt] thoughts about dip interfaces and python abstract base classes

Darren Dale dsdale24 at gmail.com
Sun Mar 13 19:01:53 GMT 2011

I've been learning about python's abstract base classes at
http://www.python.org/dev/peps/pep-3119/ and
http://docs.python.org/py3k/library/abc.html . The PEP mentions that
there is considerable overlap between ABCs and interfaces, and I'm
rereading the dip documentation on interfaces now. If I understand
correctly, dip's "implements" decorator is similar (perhaps based on)
python's abstract base class "register" class method. Is it ever the
case that dip classes actually subclass a dip interface, as python
classes would subclass one or more abstract base class?

Also, this morning I suggested on python-ideas a small tweak to
python's builtin "property" which would allow an abstract properties
to be declared using the decorator syntax. I thought it might be of
interest to dip:

import abc

class Property(property):

    def __init__(self, *args, **kwargs):
        super(Property, self).__init__(*args, **kwargs)
        if (getattr(self.fget, '__isabstractmethod__', False) or
            getattr(self.fset, '__isabstractmethod__', False) or
            getattr(self.fdel, '__isabstractmethod__', False)):
            self.__isabstractmethod__ = True

class C(metaclass=abc.ABCMeta):
    def x(self):
        return 1
    def x(self, val):

    # Can't instantiate C, C.x getter and setter are abstract
except TypeError as e:

class D(C):
    def x(self):
        return 2

    # Can't instantiate D, the D.x setter is still abstract
except TypeError as e:

class E(D):
    def x(self, val):

# E is now instantiable

More information about the PyQt mailing list