boost::python, returning new PyObject references

David Abrahams david.abrahams at rcn.com
Mon Jan 7 02:03:54 CET 2002


----- Original Message -----
From: "Guido van Rossum" <guido at python.org>

> What's the "Object Protocol"?  Are we still talking about Python here?

http://www.python.org/doc/current/api/object.html

> > I expect this
> > calls PyObject_GetItem:
> >
> > >>> 1[2]
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > TypeError: unsubscriptable object
> >
> > I would expect a KeyError or IndexError if the protocol were
> > "supported", but maybe there's a more appropriate defintion for
> > "supported" in this case.
>
> You're missing something here.  The TypeError is part of the defined
> behavior: some objects "support" the abstract "getitem" operation and
> others don't.  Not supporting "getitem" doesn't make them not an
> object.
>
> > If everything "is-a" Object, then we can ask, is a List a Number? It
> > supports some of the operations in the number protocol, after all (e.g.
+=).
> > How does one decide the answer to that question in general?
>
> By asking you to unask the question.  Python doesn't have a
> classification like this,

http://www.python.org/doc/current/api/abstract.html seems to indicate
otherwise. Also PyMapping_Check et. al, and such functions in python itself
as callable(), isinstance(), and issubclass(), though admittedly the lack of
functions like issequence() or ismapping() seems to remove the emphasis on
this idea.

I guess there's no point in arguing with GVR about the nature of Python.
FWIW, though, at least a few of us independently drew the same conclusions
about the existence and possible importance of categories based on the
documentation and the facilities provided by the language.

> so there's no point in trying.  There's a
> set of possible operations and each object type can decide which
> subset of those it supports.  Certain subsets make the type smell more
> numeric, others make it smell like a sequence, but there's no absolute
> answer.  It's *possible* though unlikely to have a sequence that
> doesn't support len(), for example.

I knew that; since the boundaries are so malleable I was trying to capture
your mental model. Maybe your mental model is actually "one big soup of
types with no structure, even informally". In that case, we may have to
rethink the idea of classification altogether.

-Dave





More information about the Cplusplus-sig mailing list