[Python-ideas] Mutable default arguments - another approach

Chris Rebert cvrebert at gmail.com
Wed Jan 31 02:54:13 CET 2007

Piotr Duda wrote:
> Read my previous post again, and give me examples of what you cannot
> do regarding default arguments.

First, I'd like to register my dislike for implicitly determining when a 
default argument will be copied on every call.

Second, as per your request:

def foo(bar=None):
     if bar is None: bar = function_call()

def foo(bar=None):
     if bar is None: bar = something.method_call()

#These were just a few. There are others.

These cannot be rewritten using simple copying decorators. Various 
decorators have been presented that account for some of these (and 
other) situations. However, IMHO they're not too elegant/clean. Thus, a 
slightly more sophisticated solution is required.

- Chris Rebert

More information about the Python-ideas mailing list