25 Feb
2014
25 Feb
'14
3:51 a.m.
On Tue, 25 Feb 2014 02:02:15 -0800 (PST) Ram Rachum <ram.rachum@gmail.com> wrote:
I'd like to have some objects that return infinity from their __len__ method. Unfortunately the __len__ method may only return an int, and it's impossible to represent an infinity as an int. Do you think that Python could allow returning infinity from __len__?
The question is what that would achieve? Consumers of len() expect it to return a finite integer, so returning infinite would break lots of existing code. If you're willing to be practical, you can still return sys.maxsize, for example (which is not far from infinite on 64-bit systems ;-)). Regards Antoine.