[pygtk] Functional/Acceptance Testing Using guitest

Michael Urman murman at gmail.com
Thu May 25 21:58:11 WST 2006


On 5/25/06, Lawrence Oluyede <l.oluyede at gmail.com> wrote:
> On 5/25/06, baiju m <baiju.m.mail at gmail.com> wrote:
> > On 5/25/06, Lawrence Oluyede <l.oluyede at gmail.com> wrote:
> > > - assert type(button) == gtk.Button
> > http://www.canonical.org/~kragen/isinstance/
>
> AFAIK the article is 4 years old and refers 2.1 version of Python. Lot
> of things have changed since 2.2 and the introduction of new style
> classes. Anyway it doesn't really matter for your example.

It's not so much that the revisions of Python have changed the times
isinstance() isn't "right", but instead that replacing isinstance with
type(foo) == bar makes the isinstance problems worse: not only do
duck-type equivalents not match, inherited classes don't match either.
Furthermore, as Lawrence implies in his last comment, in the context
of a pygtk application, the underlying hierarchy comes from the C
layer where inheritance is important, so isinstance is appropriate to
begin with.

To clarify, both Lawrence and the article really meant the same thing:
comparing types, and using insinstance, are both discouraged idioms in
python. Understand why so you can judge when your code needs to use
them anyway.

Michael
-- 
Michael Urman  http://www.tortall.net/mu/blog


More information about the pygtk mailing list