<br><br><div class="gmail_quote">On Mon, Jul 30, 2012 at 9:51 AM, Guido van Rossum <span dir="ltr">&lt;<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>&gt;</span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Also, I have a few content quibbles:<br>
<br>
- Is it really worth flagging a negative return value with ValueError?<br>
I&#39;d just as well clip this to zero. What&#39;s the worry? That the<br>
computed value is wrong? But it&#39;s only meant to be a hint, and why<br>
would -1 be any more wrong than e.g. 1000000000?<br>
<br></blockquote><div><br></div><div>This was done for consistency with len(), I&#39;m not particularly attached to any behavior.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

- Did you mean to define operator.length_hint()?<br>
<br></blockquote><div><br></div><div>Of course :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- The default can be zero with no semantic impact, so I think there&#39;s<br>
no need to require the caller to specify a default.<br>
<br></blockquote><div><br></div><div>I suppose that&#39;s fair.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- Most importantly: calling len(obj) and catching TypeError can only<br>
be a substitute for the real implementation, which IMO ought to check<br>
for the presence of a tp_len slot. Alas, checking hasattr(obj,<br>
&#39;__len__&#39;) doesn&#39;t quite cut it either, since this returns true for a<br>
class object that defines a __len__ method for its instances (the<br>
class itself doesn&#39;t have a length). Still, I worry that calling<br>
len(obj) and catching all TypeErrors overspecifies the desired<br>
behavior; what I *want* to happen is to check if there is a __len__<br>
method, and if so, call it and let any exceptions bubble through. It<br>
may be best to add a comment explaining that am implementation doesn&#39;t<br>
have to follow the letter of the Python code in the PEP, in<br>
particular, if obj *has* a __len__() method but calling it raises an<br>
exception, then length_hint(obj) may (ought to?) pass this exception<br>
on instead of calling obj.__length_hint__().<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div><br></div><div>Seems reasonable, rather than try to spec that out precisely in the pseudocode (aka Python ;)) a note like you suggest sounds good.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
--<br>
--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)<br>
</div></div></blockquote></div><br><br>Alex<br clear="all"><div><br></div>-- <br>&quot;I disapprove of what you say, but I will defend to the death your right to say it.&quot; -- Evelyn Beatrice Hall (summarizing Voltaire)<br>
&quot;The people&#39;s good is the highest law.&quot; -- Cicero<br><br>