On Thu, Feb 15, 2007 at 09:37:27PM -0800, Chris Rebert wrote: > Okay, in light of Guido's comments, alternate idea: > > We require all default values to be hash()-able, thus reasonably > ensuring their immutability.
Offhand, that's a pretty arbitrary restriction- default __hash__
for objects is their address. Majority of objects *are* mutable also,
so about all you've managed to block is usage of [] and {}, or objects
the specifically castrate their __hash__
> but at least it might stop dangerous code from being written.
<snip>
> Anything to stop the abuses of mutable default arguments.
You may not have usage for mutable default args, but others may-
namely memoization. Store the cache in the default arg.
Upshot of it, the cache isn't sitting out in the global namespace; you
can achieve the same with a memoization object/descriptor, but those
approaches break down since the key calculation can only be
args/kwargs based, rather then generating a key in a simpler way.
Further, if there *are* kwargs involved, the memoizer has to know the
default args for the target, and slip those in everytime which gets
fairly ugly.
Personally, I'm -1 on suggestions thus far- further, -1 on trying to
block mutables from default args.
Would suggest creating a tool to scan for potential issues rather then
trying to strip mutable default args from the language.
~harring
pgpQPbhsvgXoI.pgp
Description: PGP signature
_______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
