Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11674>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to