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

E731 false negatives #1061

Open
jpy-git opened this issue Mar 27, 2022 · 3 comments
Open

E731 false negatives #1061

jpy-git opened this issue Mar 27, 2022 · 3 comments

Comments

@jpy-git
Copy link

jpy-git commented Mar 27, 2022

a = lambda x: x  # Raises E731
a = (
    lambda x: x 
) # Doesn't raise E731
a, b = lambda x: x, lambda y: y  # Doesn't raise E731
a, b = 1, lambda y: y  # Doesn't raise E731
@jpy-git jpy-git changed the title E731 not raised when assigned via tuple unpacking E731 false negatives Mar 27, 2022
@Sam-Cleveland
Copy link

I think the best way to resolve this is to just mark all logical_lines with an '=' that has a 'lambda' at some point after it as having a lambda assignment. This covers all cases here and I can't think of any additional unwanted cases that this would include (as long as it is not an assignment operator or function declaration annotation, but these already checked and excluded). I'll make a PR implementing this.

@FichteFoll
Copy link
Contributor

I think the best way to resolve this is to just mark all logical_lines with an '=' that has a 'lambda' at some point after it as having a lambda assignment.

mapped = map(lambda i: i * 2, range(10))

would also be matched by this when it shouldn't, if I understood you correctly?

@Sam-Cleveland
Copy link

Oh, you're right it is not as simple as what I had said.

mapped = map(lambda i: i * 2, range(10))

In addition to this,

f.method = lambda: 'Method'

and

f['a'] = lambda x: x ** 2

both should be allowed according to tests/E73.py
Nonetheless, I came up with a regex that should only search for actual lambda assignments (making sure to account for all of the examples above). Additionally, regex is a more elegant solution than the way it was already being implemented. Making a PR.

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

Successfully merging a pull request may close this issue.

3 participants