[Python-3000] PEP 3100 Comments

Thomas Wouters thomas at python.org
Mon May 8 11:52:36 CEST 2006


On 5/8/06, Talin <talin at acm.org> wrote:
>
> Thomas Wouters <thomas <at> python.org> writes:
>
> > He is, and for the same reasons as callable(): there is no way to
> > tell whether an object is a mapping or a sequence (considering
> > Python object of both 'types' implement __getitem__, and that's
> > it. If you don't believe me, ask isSequence about UserDict.).


Some of the best Python libraries out there (IMHO) have functions
> that test their arguments to determine if they are a sequence or not.


You must have missed the part about asking isSequence about UserDict. They
may be the best in your eyes, but they're broken if they rely on isSequence
(or they impose arbitrary restrictions, if they found out isSequence doesn't
do what they want it to do.)

As an example, check out section 4: "Content Producing Constructs" in the
> Kid docs:
>
>    str, unicode - The string is inserted as XML CDATA.
>    ElementTree.Element - When an ElementTree.Element is referenced from a
>       content producing construct, the item is inserted into the document
>       literally, i.e. it is not encoded as text, but becomes part of the
> output
>       structure.
>    sequence - If a sequence type (list, tuple, or other iterable) is
> referenced,
>       the rules are applied to each of the items in the sequence. For
> example,
>       you could reference a list containing an Element and a string.
>    Other - If the result of evaluating the expression is any other type,
> an
>       attempt is made to coerce the value to unicode as if by calling
>       unicode(expr) and processing continues as if the object were a
> string
>       or unicode object initially.
>
> My reaction on reading this the first time was "Wow, what a sensible
> API!"


And mine is "Ugh, what a horribly bad API." A string *is* a sequence. Given
your description, I can never pass it a string-alike object; using
isSequence, it would be treated as a sequence before Kid tried to convert it
to unicode. Or if the test for a sequence is done by checking against known
sequence types, I wouldn't be able to pass a custom sequence type. The user
of the code knows what kind of object he's passing, how he wants it to be
treated. Having the code guess is quite fragile.

Nothing is going to stop you to make the same guessing and harebrained
assumptions in Py3K, you just won't have the broken 'operator.isSequence'
test to do it for you (and imply it knows what it's talking about.) You will
have to write your own guesswork.

I would hate to be told that I'm not allowed to test whether something
> is a sequence or not.


Python doesn't care where you point your gun, whether you pull the trigger
or not. It's just not going to give you a point-at-foot device; you'll have
to write that yourself.

--
Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20060508/3747c7f4/attachment.html 


More information about the Python-3000 mailing list