Builtin dict should be callable, since a dict defines a function
Erik Max Francis
max at alcyone.com
Thu Dec 19 21:17:03 EST 2002
Bengt Richter wrote:
> I posted the suggestion in a thread Re: case-insensitive and
> internationalized sort,
> but it occurs to me that the principle is arguable from the abstract
> point of view.
> I.e., a dict implements a function key -> value, so why not let it
> accept a normal
> function arg list (i.e., the tuple) as the argument for its key ->
> value function?
> It should be a pretty simple change to provide __call__(self, *args):
> return self[args]
> under the hood, and let hashability chips fall where they will via [].
But why would this be helpful? A dictionary implements a mappable
interface; a function implements are callable interface. They're
different interfaces; why would dovetailing them into the same interface
be beneficial?
It's a simple change, sure, but furthermore it's trivial enough for you
to implement it yourself in a subclass of dict.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ I'm trying to forget / But I can't act as if we never met
\__/ Chante Moore
PyUID / http://www.alcyone.com/pyos/uid/
A module for generating "unique" IDs in Python.
More information about the Python-list
mailing list