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 vstinner
Recipients Yoni Lavi, mark.dickinson, rhettinger, steven.daprano, taleinat, vstinner
Date 2019-12-19.11:12:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576753926.23.0.0437809592277.issue39094@roundup.psfhosted.org>
In-reply-to
Content
> I've tried think of other solutions, such as a generic wrapper for such functions or a helper to check whether an iterable is empty, and they all turn out to be very clunky to use and un-Pythonic.

So the main use case would be to detect an empty iterable in an efficient fashion? Something like the following code?

sentinel = objet()
avg = mean(data, default=sentinel)
if avg is sentinel:
   ... # special code path

Why not adding a statistics.StatisticsError subclass for empty set (ex: StatisticsEmptyError)? Something like:

try:
   avg = mean(data)
except statistics.StatisticsEmptyError:
   ... # special code path, ex: avg = default

Or is there another use case for the proposed default parameter?
History
Date User Action Args
2019-12-19 11:12:06vstinnersetrecipients: + vstinner, rhettinger, mark.dickinson, taleinat, steven.daprano, Yoni Lavi
2019-12-19 11:12:06vstinnersetmessageid: <1576753926.23.0.0437809592277.issue39094@roundup.psfhosted.org>
2019-12-19 11:12:06vstinnerlinkissue39094 messages
2019-12-19 11:12:06vstinnercreate