<br><div><span class="gmail_quote">On 5/8/06, <b class="gmail_sendername">Talin</b> <<a href="mailto:talin@acm.org">talin@acm.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thomas Wouters <thomas <at> <a href="http://python.org">python.org</a>> writes:<br><br>> He is, and for the same reasons as callable(): there is no way to<br>> tell whether an object is a mapping or a sequence (considering
<br>> Python object of both 'types' implement __getitem__, and that's<br>> it. If you don't believe me, ask isSequence about UserDict.).</blockquote><div><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Some of the best Python libraries out there (IMHO) have functions<br>that test their arguments to determine if they are a sequence or not.</blockquote><div><br>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.)
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">As an example, check out section 4: "Content Producing Constructs" in the
<br>Kid docs:<br><br> str, unicode - The string is inserted as XML CDATA.<br> ElementTree.Element - When an ElementTree.Element is referenced from a<br> content producing construct, the item is inserted into the document
<br> literally, i.e. it is not encoded as text, but becomes part of the output<br> structure.<br> sequence - If a sequence type (list, tuple, or other iterable) is referenced,<br> the rules are applied to each of the items in the sequence. For example,
<br> you could reference a list containing an Element and a string.<br> Other - If the result of evaluating the expression is any other type, an<br> attempt is made to coerce the value to unicode as if by calling
<br> unicode(expr) and processing continues as if the object were a string<br> or unicode object initially.<br><br>My reaction on reading this the first time was "Wow, what a sensible<br>API!"</blockquote>
<div><br>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.
<br><br>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.
</div><div><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I would hate to be told that I'm not allowed to test whether something<br>
is a sequence or not.</blockquote><div><br>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.<br>
</div><br></div>-- <br>Thomas Wouters <<a href="mailto:thomas@python.org">thomas@python.org</a>><br><br>Hi! I'm a .signature virus! copy me into your .signature file to help me spread!