[PEAK] Bug(?) Rules istype is upgraded to isinstance

Phillip J. Eby pje at telecommunity.com
Mon Mar 3 10:27:04 EST 2008

At 05:20 PM 3/3/2008 +0200, Sergey Schetinin wrote:
>It seems that istype(cls) is not converted to a type comparision but
>to an `isinstance' check when upgrading the matching engine. Here's
>the code from the PEAK-Rules source:
>when(type_to_test, (istype,))
>def istype_to_test(typ, expr, engine):
>     return Test(IsInstance(expr), typ)

That bit's correct, actually.  What's missing is that istype() tests 
aren't properly indexed, such that an IsInstance test on an istype 
does the right thing.  They should be indexed in such a way that 
they're equivalent to isinstance(x, typ) and not isinstance(x, 
any-subtype-of-type).  The index and dispatch machinery is quite 
capable of doing this, it's just not implemented yet.

Fixing it is on my to-do list for the first alpha release.

More information about the PEAK mailing list