Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tuple parameter unpacking not removed for some lambdas #15

Open
daira opened this issue Aug 12, 2014 · 5 comments
Open

tuple parameter unpacking not removed for some lambdas #15

daira opened this issue Aug 12, 2014 · 5 comments

Comments

@daira
Copy link
Contributor

daira commented Aug 12, 2014

    d.addCallback(lambda (rc, out, err), fn=fn:
                  self.failUnlessEqual(out, fn * 1000))

I would have expected this to be changed to something like

    d.addCallback(lambda rc_and_out_and_err, fn=fn:
                  self.failUnlessEqual(rc_and_out_and_err[1], fn * 1000))

(moved from mitsuhiko/python-modernize#23 )

@takluyver
Copy link
Contributor

Playing with it a bit, it appears to only work if the lambda only has one argument. However, the code for this is in lib2to3, so it's not easy for us to fix.

@takluyver
Copy link
Contributor

Yep, this is tracked in the Python bug tracker: http://bugs.python.org/issue16094

@daira
Copy link
Contributor Author

daira commented Aug 13, 2014

It looks like they're not going to fix it, though (with reasoning I consider invalid).

This is a big issue for modernizing Tahoe-LAFS, which has hundreds of these lambdas.

@daira daira removed this from the Release 0.3.1 milestone Aug 13, 2014
@takluyver
Copy link
Contributor

If it's important, we can copy and modify the fixer from 2to3:
http://hg.python.org/cpython/file/4d4a9094bdb0/Lib/lib2to3/fixes/fix_tuple_params.py

That code looks pretty involved, though.

@daira daira added this to the Release 0.5 milestone Sep 27, 2014
@daira
Copy link
Contributor Author

daira commented Jan 10, 2015

I think I see the problem: the fixer pattern is just not matching on a case like lambda (rc, out, err), fn=fn: ... because it is expecting parens around the whole parameter list.

The discussion in http://bugs.python.org/issue16094 is confused/wrong, because they're complaining about issues for which the fixer design has already chosen the same compromises for other very similar cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants