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 erik.bray
Recipients bbayles, erik.bray, jdemeyer, ncoghlan, pitrou, rhettinger, serhiy.storchaka
Date 2018-06-27.14:50:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1530111004.12.0.56676864532.issue33939@psf.upfronthosting.co.za>
In-reply-to
Content
> Thinking about the generator-iterator case a bit more, "False" would be a bad default for that. Allowing "NotImplemented" to indicate the ambiguous "Might be finite, might be infinite" state, and using that as the default for generator-iterators, would probably make sense.

This is why I suggested the converse--something like __finite_iterator__ (nevermind bikeshedding over the name or "yet another dunder method).  This is something one would use to mark as iterator as "this is definitely expected to terminate at some point, assuming it is correctly implemented".  

If __finite_iterator__ == False, which should be the default, it doesn't necessarily mean it is infinite either, it just may or may not be finite, so there's no guarantee.

I think that __finite_iterator__ == True is more or less equivalent to returning a non-zero value from __length_hint__, whereas __finite_iterator__ == False is equivalent to raising NotImplemented for __length_hint__.  Either way it means adding __length_hint__ to all iterators, and also (as Nick suggested) having a decorator for generators to set the appropriate hint as well.
History
Date User Action Args
2018-06-27 14:50:04erik.braysetrecipients: + erik.bray, rhettinger, ncoghlan, pitrou, serhiy.storchaka, jdemeyer, bbayles
2018-06-27 14:50:04erik.braysetmessageid: <1530111004.12.0.56676864532.issue33939@psf.upfronthosting.co.za>
2018-06-27 14:50:04erik.braylinkissue33939 messages
2018-06-27 14:50:03erik.braycreate