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, benjamin.peterson, rhettinger, stutzbach, terry.reedy
Date 2011-04-01.23:06:36
SpamBayes Score 2.2870594e-14
Marked as misclassified No
Message-id <1301699197.28.0.373628590338.issue11674@psf.upfronthosting.co.za>
In-reply-to
Content
Am going to close this one because I don't see any straight-forward way around it and because it's technically not a bug (just an undesirable design artifact).  The use of TypeError for objects that don't define __len__ is deeply ingrained into Python (20 years).  If something inside a __len__ method raises a TypeError, it would be challenging to distinguish that from a missing __len__ method.  

[terry]
It might be possible to create internal subclasses of TypeError, AttributeError and whatnot, but that is a deep change with unknown implications for users, for other python implementations, for performance, for third-party modules, etc.  It would need a PEP and is likely to get rejected on a cost-benefit basis -- the substantial API churn wouldn't be worth the microscopic benefit (i.e. most people never encounter this or care about it).

[benjamin]
The __length_hint__ protocol is a public API, so anyone can use it.  Also, the issue is a broader than __length_hint__, it is really distinguishing multiple possible meanings for a TypeError raised by a call to __len__.
History
Date User Action Args
2011-04-01 23:06:37rhettingersetrecipients: + rhettinger, terry.reedy, amaury.forgeotdarc, benjamin.peterson, stutzbach, Elvis.Pranskevichus
2011-04-01 23:06:37rhettingersetmessageid: <1301699197.28.0.373628590338.issue11674@psf.upfronthosting.co.za>
2011-04-01 23:06:36rhettingerlinkissue11674 messages
2011-04-01 23:06:36rhettingercreate