[Types-sig] Re: documenting Python constraints on types

Frederic Giacometti frederic.giacometti@arakne.com
Sat, 02 Jun 2001 08:03:28 -0400


Jeremy Hylton wrote:

> >>>>> "FG" == Frederic Giacometti <frederic.giacometti@arakne.com> writes:
>
>
>   FG> A 'mapping' is an object that 'implements' the object protocol
>   FG> (PyMapping_Check()... ok).  I think that everybody's interessest
>   FG> is in working for a small set of standard interface definitions.
>
> What's a sequence then?  If you say anything that PySequence_Check()
> says okay for, then there is almost no code that accepts a sequence.
> In both cases, we would appear to skip instances that implement the
> sequence or mapping protocols, which are accepted most places that
> sequences or mappings are accepted.

OK. Taking the C check function as reference may not be the right thing
(Then you might ask; Are the PySequence_Check and PyMapping_Check functions of
any use other than checking that the the desiring protocol field has a
non-null value in the C type defintion? ... but that's another debate).

I guess some further definition and formalizing work is required for the basic
Python types / protocol.
Here is a step forward:
In the same spirit as in the read-only / writable Mapping, you may define:

- "Tuple" (as a non-mutable read-only sequence0
- "Vector" (items can be changed, but the sequence size is frozen, just like
in a vector object)
- List (anything can be done on it; modifying items, adding/removing items;
just like a plain list).

Here again, with these three hierarchical protocol/interfaces (each one add
feature the previous did not have), you cover 98% of the sequence situations.

FG