This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients Elvis.Pranskevichus, amaury.forgeotdarc, rhettinger, stutzbach
Date 2011-03-25.22:23:26
SpamBayes Score 3.0267317e-06
Marked as misclassified No
Message-id <1301091807.68.0.599133541383.issue11674@psf.upfronthosting.co.za>
In-reply-to
Content
A certain amount of exception masking is inherent is Python's design.  We use TypeError for a lot of things, including the exception raised by "len(obj)" when obj doesn't have length.

It may be possible to replace the TypeError check with test to set if __len__ is defined, but that would subtly change the semantics.  For example, if a class defined __len__ to raise a TypeError to indicate that the length is unknown (I've seen code like this in the wild being used to distinguish between finite inputs and potentially infinite inputs).

I don't really like the current design of __length_hint__, but it has been around for years and is somewhat set in stone.  If something does get changed, it should only be in Py3.3 so we don't break code that relies on the current behaviors.
History
Date User Action Args
2011-03-25 22:23:27rhettingersetrecipients: + rhettinger, amaury.forgeotdarc, stutzbach, Elvis.Pranskevichus
2011-03-25 22:23:27rhettingersetmessageid: <1301091807.68.0.599133541383.issue11674@psf.upfronthosting.co.za>
2011-03-25 22:23:26rhettingerlinkissue11674 messages
2011-03-25 22:23:26rhettingercreate