[Python-ideas] statistics module in Python3.4

Chris Angelico rosuav at gmail.com
Fri Jan 31 02:32:04 CET 2014


On Fri, Jan 31, 2014 at 12:07 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> One of my aims is to avoid raising TypeError unnecessarily. The
> statistics module is aimed at casual users who may not understand, or
> care about, the subtleties of numeric coercions, they just want to take
> the average of two values regardless of what sort of number they are.
> But having said that, I realise that mixed-type arithmetic is difficult,
> and I've avoided documenting the fact that the module will work on mixed
> types.

Based on the current docs and common sense, I would expect that
Fraction and Decimal should normally be there exclusively, and that
the only type coercions would be int->float->complex (because it makes
natural sense to write a list of "floats" as [1.4, 2, 3.7], but it
doesn't make sense to write a list of Fractions as [Fraction(1,2),
7.8, Fraction(12,35)]). Any mishandling of Fraction or Decimal with
the other three types can be answered with "Well, you should be using
the same type everywhere". (Though it might be useful to allow
int->anything coercion, since that one's easy and safe.)

ChrisA


More information about the Python-ideas mailing list