[Python-Dev] Do we need length_hint at all? (Was PEP 0424: A method for exposing a length hint) (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Mon Jul 16 15:23:18 CEST 2012


On Mon, Jul 16, 2012 at 7:21 PM, Tim Golden <mail at timgolden.me.uk> wrote:

Speaking of which - I find this bikeshed disgusting. Disgusting? Irritating, perhaps, but why should a PEP -- even one whose purpose is to codify existing practice -- not result in discussions about its subject matter? The final P stands for Proposal, not for Pronouncement.

Indeed - I'd be worried if any PEP sailed through python-dev review without a thorough kicking of the tires. Yes, it can be annoying having to bring people up to speed on issues that they aren't familiar with, but that's generally a sign that there is relevant background information missing from the PEP.

PEP's aren't supposed to be written just for people that are already intimately familiar with a problem - they're supposed to provide enough background that they stand on their own.

In this case, the key points that I think need to be added:

As well as any user defined sequence that relies on the default sequence iterator: >>> class MySeq(): ... def getitem(self, idx): ... return idx ... def len(self): ... return 10 ... >>> hasattr(iter(MySeq()), "length_hint") True

That's the basic proposal. Separate from that, there are a few suggestions for enhancement beyond what CPython currently uses (and has demonstrated a clear need for):

My main point is that the current length_hint behaviour has already proven its value in the real world. The PyPy team would like that behaviour codified, so they can be reasonably sure both implementations are doing the same thing. Many of the enhancements I have listed above may be suitable material for future enhancement proposals, but I'm not seeing any requested functionality that would be actively blocked by simply codifying the status quo.

The PEP itself already has this general tone, but I think that it should be even more emphatic that it's about codifying the status quo, not about modifying it with ideas haven't been proven useful through past experience.

Cheers, Nick.

-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia



More information about the Python-Dev mailing list