[Python-3000] pre-PEP: Default Argument Expressions

Brian Harring ferringb at gmail.com
Fri Feb 16 08:01:04 CET 2007


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20070215/32844399/attachment.pgp 


More information about the Python-3000 mailing list