Making Classes Subclassable
Lawrence D’Oliveiro
lawrencedo99 at gmail.com
Tue Jul 5 23:04:25 EDT 2016
On Monday, July 4, 2016 at 7:58:07 PM UTC+12, dieter wrote:
>
> Lawrence D’Oliveiro writes:
>
> > Some of the classes in Qahirah, my Cairo binding
> <https://github.com/ldo/qahirah> I found handy to reuse elsewhere, for
> example in my binding for Pixman <https://github.com/ldo/python_pixman>.
> Subclassing is easy, but then you need to ensure that operations inherited
> from the superclass return instances of the right class. This means that
> superclass methods must never refer directly to the class by name for
> constructing new objects; they need to obtain the current class by more
> indirect means.
>
> --> "type(obj)" or "obj.__class__" (there are small differences)
> give you the type/class of "obj".
OK, both updated.
Funny how you find other bugs when revisiting code after a while. :)
More information about the Python-list
mailing list