Making Classes Subclassable

dieter dieter at handshake.de
Mon Jul 4 03:57:27 EDT 2016


Lawrence D’Oliveiro <lawrencedo99 at gmail.com> 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".




More information about the Python-list mailing list