lambda-py icon indicating copy to clipboard operation
lambda-py copied to clipboard

tuple assignment to class members fails

Open mpmilano opened this issue 12 years ago • 2 comments

class c: pass c.x, c.y = (5,6)

reports exception: can't assign to literals

this works in python. This makes solving the destructuring bind bug for classes somewhat tricky. I've worked around it, but when this is solved I'l like to remove the workaround.

mpmilano avatar Mar 28 '13 05:03 mpmilano

Our destructuring assignment really only works with tuples of literals, I think.

I played with that a little bit last week; to do it right we really need to define an entire tree-walk over LHS expressions, and build an AST that exercises a tree of iterators on the right. It's hairy stuff:

def f(): ... yield 'fun' ... yield 'times' ... [(a,b),(c,d)] = {f(), f()} a 'fun' b 'times' c 'fun' d 'times'

On Thu, Mar 28, 2013 at 1:24 AM, Matthew Milano [email protected]:

class c: pass c.x, c.y = (5,6)

reports exception: can't assign to literals

this works in python. This makes solving the destructuring bind bug for classes somewhat tricky. I've worked around it, but when this is solved I'l like to remove the workaround.

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/58 .

jpolitz avatar Mar 28 '13 05:03 jpolitz

For the ambitious, I bet you can probably segfault Python somewhere in here by using an LHS that has a property that calls a generator that's in the middle of an iteration on the RHS or something similarly insane.

On Thu, Mar 28, 2013 at 1:35 AM, Joe Gibbs Politz [email protected] wrote:

Our destructuring assignment really only works with tuples of literals, I think.

I played with that a little bit last week; to do it right we really need to define an entire tree-walk over LHS expressions, and build an AST that exercises a tree of iterators on the right. It's hairy stuff:

def f(): ... yield 'fun' ... yield 'times' ... [(a,b),(c,d)] = {f(), f()} a 'fun' b 'times' c 'fun' d 'times'

On Thu, Mar 28, 2013 at 1:24 AM, Matthew Milano [email protected]:

class c: pass c.x, c.y = (5,6)

reports exception: can't assign to literals

this works in python. This makes solving the destructuring bind bug for classes somewhat tricky. I've worked around it, but when this is solved I'l like to remove the workaround.

— Reply to this email directly or view it on GitHubhttps://github.com/brownplt/lambda-py/issues/58 .

jpolitz avatar Mar 28 '13 05:03 jpolitz