[Python-Dev] PEP 450 adding statistics module

Eric V. Smith eric at trueblade.com
Fri Aug 16 05:40:45 CEST 2013


On 8/15/2013 10:44 PM, Steven D'Aprano wrote:
> On 16/08/13 04:10, Eric V. Smith wrote:
> 
>> I agree with Mark: the proposed median, median.low, etc., doesn't feel
>> right. Is there any example of doing this in the stdlib?
> 
> The most obvious case is datetime: we have datetime(), and
> datetime.now(), datetime.today(), and datetime.strftime(). The only API
> difference between it and median is that datetime is a type and median
> is not, but that's a difference that makes no difference: both are
> callables, and being a type is an implementation detail. dict used to be
> a function that returned a type. Now it is a type. Implementation detail.
> 
> Even builtins do this: dict() and dict.fromkeys(), for example. 

Except those classmethods are all alternate constructors for the class
of which they're members (it's datetime.strptime, not .strftime). That's
a not uncommon idiom. To me, that's a logical difference from the
proposed median.

I understand it's all just namespaces and callables, but I think the
proposed median(), median.low(), etc. just confuse users and makes
things less discoverable. I'd expect dir(statistics) to tell me all of
the available functions in the module. I wouldn't expect to need to look
inside all of the returned functions to see what other functions exist.

To see what I mean, look at help(itertools), and see how much harder it
is to find chain.from_iterable than it is to find
combination_with_replacement.

BTW, I'm +1 on adding the statistics module.

-- 
Eric.


More information about the Python-Dev mailing list