Re: [Types-sig] Re: documenting Python constraints on types
by Frederic Giacometti other posts by this author
Jun 2 2001 12:03PM messages near this date
[Types-sig] Re: Almost ready for prime time (sorry!)
|
RE: [Types-sig] Re: documenting Python constraints on types
Jeremy Hylton wrote:
> >>>>> "FG" == Frederic Giacometti <frederic.giacometti@[...].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
Thread:
Michel Pelletier
Michel Pelletier
Frederic Giacometti
Tim Peters
Frederic Giacometti
|