[Types-sig] QueryProtocol

Paul Prescod paulp@ActiveState.com
Wed, 21 Mar 2001 10:04:58 -0800


"Clark C. Evans" wrote:
> 
>...
> 
> I was vague here beacuse I didn't know what to do.
> Perhaps "None" should be returned?

That would probably be easiest. If the caller wants to require an
interface, they can throw the exception themself.

> ...
> > >     In addition, a built-in query method could be introduced that
> > >     calls the __query__ method on a given object.
> >
> > You mean "query function."
> 
> How about "query object"

If you are talking about a built-in function, you should call it a
built-in function. like hasattr, getattr, etc.

>...
> > I don't know much about __iter__ but my first instinct is to be careful
> > there. When you return an interface, you are semantically returning a
> > view into the object. When you return an iterator, you are semantically
> > returning another object that happens to have special knowledge of the
> > first. In other words, interfaces should have no state. Iterators are
> > *all* state. :)
> 
> An iterator is a "view" of a particular object.  The state
> the view must maintain depends upon the requirements.
> I don't see any semantic difficulty here at all.

Here's my definition of "view". If x and y are views over the same
object then at any time I should be able to call x.foobar() or
y.foobar() and expect to get back the same result. If x.foobar() can
return a different result than y.foobar() then the objects are really
different objects, not just views into a single object.

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook