<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Oleg Broytmann a écrit :
<blockquote cite="mid:20090519203409.GA17197@phd.pp.ru" type="cite">
  <pre wrap="">On Tue, May 19, 2009 at 10:31:00PM +0200, Pascal Chambon wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">I could content myself of the proposed solution :
@dynamic
def func (a, b = lambda : []):
   pass
But I just dislike the fact that the "dynamic" applies to all the  
defaults, even those which weren't supposed to be dynamic (and writing  
"lambda : lambda : []") doesn't look good).
Would there be any way of separating "to-be-called" lambdas from normal  
ones ? Except with a syntax like "b = dyn(lambda: [])" ?
    </pre>
  </blockquote>
  <pre wrap=""><!---->
@dynamic('b')
def func (a, b = lambda : []):
    pass

Oleg.
  </pre>
</blockquote>
*shame on me - /me must be tired this evening*<br>
<br>
Well, with that solution we don't avoid some amount of boiler plate
code, but imo the pros are<br>
- we don't have to care about copy/deepcopy constraints, or giving the
default argument expression as a string (with all the problems eval()
might raise)<br>
- most important for me : we have a pattern that could be broadcasted
as a "standard practice", and thus warn newbies about the normal
behaviour of default arguments.<br>
If the "dynamic" (or any other proper name) decorator became part of
the builtin ones, like staticmethod or classmethod, in my opinion
newbies would quickly run into it, get used to it, and we'd have a
common practice instead of the numerous ones currently possible to
handle dynamic defaults (sentinels, other decorators...).<br>
<br>
What do you think ? Is that worth the change compared to the sentinel
stuff ? <br>
In my opinion, it's clearly more explicit, and the newbie will never
think "that programmer is dumb, he has put None as a default whereas we
can directly put lists or any other expressions in the signature, we're
not restricted to constants like in other languages" as it might
currently be the case.<br>
<br>
I'm eventually +1 on such a decorator/lambda mix (in the absence of
more straightforward but language-changing syntax)<br>
<br>
++<br>
Pascal<br>
</body>
</html>