Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99212 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2015-11-21 08:01 -0700 |
| Last post | 2015-11-21 08:01 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-21 08:01 -0700
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-11-21 08:01 -0700 |
| Subject | Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) |
| Message-ID | <mailman.38.1448118113.2291.python-list@python.org> |
On Sat, Nov 21, 2015 at 1:46 AM, Chris Angelico <rosuav@gmail.com> wrote: > On Sat, Nov 21, 2015 at 7:38 PM, Todd <toddrjen@gmail.com> wrote: >> Rather than a dedicated syntax, might this be something that could be >> handled by a built-in decorator? >> >> Maybe something like: >> >> @late_binding >> def myfunc(x, y=[]): > > No, it can't; by the time the decorator runs, the expression has > already been evaluated. Without syntax, this can only be done with > gross hacks like lambda functions. > > It could be done thus: > > @late_binding > def myfunc(x, y=lambda: []): > > and then the decorator could wrap the function. I'm not entirely sure > I could implement it reliably, but even leaving that aside, having to > put "lambda:" in front of everything is pretty ugly. Note that "lambda: []" can also be spelled "list".
Back to top | Article view | comp.lang.python
csiph-web