Ben Roberts added the comment: > The major issue (there are other issues as well but not so difficult) is > whether nlargest and nsmallest should support iterator that could be endless > iterator or reject it (by checking __len__ attribute) straight away.
Well, failing with an exception isn't right. I can imagine doing (and probably have done, at some point) nlargest on any number of generators, streams of data, etc. So unless anyone can solve the halting problem (:-)) the behavior of nlargest is correct as possible; nlargest(2, GetOnly()) behaves just like list(GetOnly()) - they both hang forever. The proper action here is just a fix in the tests: make GetOnly raise IndexError at some point so that it is a proper sequence. (also rename the second test to get_cmp_only) ---------- nosy: +roippi _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19119> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com