[cairo] pycairo subclass

Steven Chaplin stevech1097 at yahoo.com.au
Wed Dec 12 03:50:52 PST 2007


On Wed, 2007-12-12 at 09:02 -0200, Solerman Kaplon wrote:
> Steven Chaplin escreveu:
> > One way to write the Python bindings for cairo would be as a single
> > long list of module functions - this would be the most accurate
> > representation of the underlying C library. Pycairo (and most other
> > cairo language bindings?) instead chose to implement the bindings using
> > Context, Surface, Pattern, etc classes.
> > An advantage is that the classes organise cairo into groups of similar
> > functions.
> > A disadvantage is that creates an illusion that cairo is object
> > oriented library, and people are then tempted to create subclasses to
> > override cairo methods. When in fact there are no methods to
> > override, just cairo functions which can't be overridden.
> >   
> 
> I lost the first part of the thread, so if nobody asked yet, can the 
> classe be marked as final in python or some language-equivalent construct?
> 
> Solerman

The PyTypeObject has a field 'tp_flags', which is a bit mask of various
flags. One of the bits is
Py_TPFLAGS_BASETYPE
        This bit is set when the type can be used as the base type of
        another type. If this bit is clear, the type cannot be subtyped
        (similar to a "final" class in Java).

This flag is used in the pycairo binding written in C, but I don't
think you can read this flag from Python. You can only try to create
a subclass and receive an error when its not set (?).

Steve



More information about the cairo mailing list