[pygtk] Functional/Acceptance Testing Using guitest
Doug Quale
quale1 at charter.net
Thu May 25 22:04:05 WST 2006
Chris Lambacher <chris at kateandchris.net> writes:
> The article is still relevant. However it is often quoted to support
> something that I think the author did not intend. The true point point of the
> article is that if you use isinstance you can't use duck typing.
> Unfortunately checking for a supported interface is often difficult in python
> because there is no standard way for an object to say "I support interface x".
> That leaves people doing a lot of isinstance because it is easy. More often
> we just care that an object supports a couple of method calls an has one or
> two attributes or properties. Python gives us the means to test for that, but
> it is certainly not as easy as using is instance.
Those same concerns apply even more strongly to "type", however, so
there are few cases in which type is preferred to isinstance. It's
best to avoid both of them if you can. If you can't, isinstance is
usually better than type. I think instance is better in this
particular case for the reasons you explain next:
> As for the particular bit of code up for debate:
> assert type(button) == gtk.Button
>
> This will work for Baiju's purposes but isinstance would also allow him to
> accept anything that inherits from gtk.Button (currently that means
> gtk.ColorButton, gtk.FontButton, gtk.ToggleButton, gtk.CheckButton,
> gtk.RadioButton).
More information about the pygtk
mailing list