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

E741: Inconsistent behavior for lambdas #959

Closed
knkski opened this issue Aug 12, 2020 · 3 comments · Fixed by #1106
Closed

E741: Inconsistent behavior for lambdas #959

knkski opened this issue Aug 12, 2020 · 3 comments · Fixed by #1106

Comments

@knkski
Copy link

knkski commented Aug 12, 2020

It seems like E741 shouldn't apply to variable names inside of comprehensions, due to the limited scope of such variables. If that's the desired behavior anyways, this behavior seems inconsistent to me:

# flagged as lint
foo = [l for l in lines if l]

# not flagged as lint
foo = list(filter(lambda l: l, lines))
@asottile
Copy link
Member

I believe it's just a mistake that this isn't handled for lambdas

the rule is correct for the list comprehension due to the ability to confuse:

foo = [l for l in lines if l]
foo = [1 for l in lines if 1]

@asottile asottile changed the title Inconsistent behavior for E741 E741: Inconsistent behavior for lambdas Aug 12, 2020
@pktiuk
Copy link

pktiuk commented Jun 3, 2021

I have this issue, but in my case it is clearly inconsistent:

COMP_OPERATIONS = {
    "==": lambda l, r: l == r,   # This is falgged
    ">=": lambda l, r: l >= r,   # This is falgged
    "<=": lambda l, r: l <= r,   # This is falgged
    ">": lambda l, r: l > r,  # This is not flagged
    "<": lambda l, r: l < r,  # This is not flagged
}

@asottile
Copy link
Member

asottile commented Jun 3, 2021

@pktiuk yeah it's not enabled for lambdas at all at the moment -- it's detecting l >= r as an assignment (?)

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