Re: SystemError when defining

2011-11-05 Thread Terry Reedy
On 11/4/2011 9:53 PM, Joshua Landau wrote: Joshua found bugs.python.org and, 2 hours later, a fix was applied. http://bugs.python.org/__issue13343 It was impressively fast. Those python devs are like a hawk. Although I wasn

Re: SystemError when defining

2011-11-04 Thread Joshua Landau
> > Joshua found bugs.python.org and, 2 hours later, a fix was applied. > http://bugs.python.org/**issue13343 > It was impressively fast. Those python devs are like a hawk. Although I wasn't expecting a three-line patch (plus a three line test). -- http://mail.

Re: SystemError when defining

2011-11-04 Thread Terry Reedy
On 11/4/2011 3:10 PM, Joshua Landau wrote: > >> def x(nonlocal_var): ... def y(): ... z = lambda *, keyword_only=nonlocal_var: None ... return y ... >>> x(None)() ... SystemError: no locals when loading 'nonlocal_var' ... Now - where shall I re

Re: SystemError when defining

2011-11-04 Thread Joshua Landau
> > >>> def x(nonlocal_var): ... def y(): ... z = lambda *, keyword_only=nonlocal_var: None ... return y ... >>> x(None)() Traceback (most recent call last): File "", line 1, in File "", line 3, in y SystemError: no locals when loading 'nonlocal_var' >>> dis.dis(x

Re: SystemError when defining

2011-11-04 Thread Joshua Landau
On 11/3/11, Chris Angelico wrote: > Fascinating! Awesome to know! > I did some introspection with this: > *snip* > > Variations on the theme show that during compilation of foo, the name > is normally cemented as either a global or a local - but if it's > keyword-only, then a LOAD_NAME opcode is

Re: SystemError when defining

2011-11-03 Thread Chris Angelico
On Fri, Nov 4, 2011 at 9:24 AM, Joshua Landau wrote: > Non-lambdas work as expected, but a lambda inside a non-lambda still > exhibits this behaviour. > Conclusion: > When setting defaults to keyword-only arguments in lambdas which are inside > non-global scopes, cPython is unable to access the gl

SystemError when defining

2011-11-03 Thread Joshua Landau
Try this out (Python 3.2.2 (default, Sep 5 2011, 04:52:19)): global_variable = None > (lambda *, keyword_only=global_variable: None) # Works, as > expected > (lambda: (lambda argument=global_variable: None))()# Works, as > expected > (lambda: (lambda *, keyword_only=global_var