[Python-Dev] Requesting pronouncement on PEP 0424 (original) (raw)

Guido van Rossum guido at python.org
Mon Jul 30 19:09:17 CEST 2012


If you give my second patch an LGTM I'll submit it and you're done.

On Mon, Jul 30, 2012 at 9:58 AM, Alex Gaynor <alex.gaynor at gmail.com> wrote:

On Mon, Jul 30, 2012 at 9:51 AM, Guido van Rossum <guido at python.org> wrote:

Also, I have a few content quibbles: - Is it really worth flagging a negative return value with ValueError? I'd just as well clip this to zero. What's the worry? That the computed value is wrong? But it's only meant to be a hint, and why would -1 be any more wrong than e.g. 1000000000? This was done for consistency with len(), I'm not particularly attached to any behavior.

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

-- --Guido van Rossum (python.org/~guido)



More information about the Python-Dev mailing list