[Python-ideas] proto-PEP: Fixing Non-constant Default Arguments
collinw at gmail.com
Tue Jan 30 05:36:51 CET 2007
On 1/28/07, Chris Rebert <cvrebert at gmail.com> wrote:
> There was some concern over the possible performance
> hit this could cause, and whether there should be new syntax so that
> code could use the existing semantics for performance reasons. Some of
> the proposed syntaxes were:
> def foo(bar=<baz>):
> def foo(bar=new baz):
> def foo(bar=fresh baz):
> def foo(bar=separate baz):
> def foo(bar=another baz):
> def foo(bar=unique baz):
> where the new keyword (or angle brackets) would indicate that the
> parameter's default argument should use the new semantics.
Syntax changes are a huge stick to wield against such a small problem.
I realize the boilerplate is annoying, but Tomer has pointed out a
number of decorator-based solutions  that could easily be adapted
to any unusual needs you have.
Also, you haven't talked at all about how all this might be
accomplished. You say
> Given these semantics, it makes more sense to refer to default argument
> expressions rather than default argument values, as the expression is
> re-evaluated at each call, rather than just once at definition-time.
but how do you intend to capture these "default argument expressions"?
Emit additional bytecode for functions making use of these special
More information about the Python-ideas