[Types-sig] QueryProtocol
Paul Prescod
paulp@ActiveState.com
Tue, 20 Mar 2001 18:24:31 -0800
"Clark C. Evans" wrote:
>
>...
> A new built-in method, __query__ is proposed. This method has
> a single argument, an interface protocol identifier, and either
> returns an object supporting the given protocol, or throws an
> unknown exception.
What do you mean by "unknown exception". "UnknownInterface" exception?
> An interface protocol identifier is a lower-case string having
> a reverse DNS host name string:
Why a string? What if we let an interface be any object and we used
object identity to compare them? That way we don't have to introduce a
new namespace into Python. I have never seen a reverse-DNS string in a
Python program and I am leery of adding the concept.
Maybe we will standardize the structure of interface objects and maybe
we won't. Maybe we will standardize them some time in the future. I
think that the addressing mechanism should be the Python namespace and
not the reverse domain namespace.
> In addition, a built-in query method could be introduced that
> calls the __query__ method on a given object.
You mean "query function."
> The iterator special interest group is proposing a new built-in
> called "__iter__", which could be replaced with __query__ and
> a blessed interface protocol identifier of "enumerator".
> Therefore calls to obj.__iter__() could be replaced with
> obj.__query__("enumerator") with no semantic difference.
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. :)
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.activestate.com/pythoncookbook