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

loop-invariant-statement triggered by dict creation in else branch of for-else #38

Open
jakkanen opened this issue Dec 26, 2022 · 0 comments

Comments

@jakkanen
Copy link

The following incorrectly results in perflint_issue.py:6:15: W8201: Consider moving this expression outside of the loop. (loop-invariant-statement)

def findfirstkey(items, key):
    for item in items:
        if item["key"] == key:
            return item
    else:
        return {"key": key}

Interestingly, the diagnostic is printed twice for each key-value pair if the dict is created with {"key": key, "key2": None} and once for each key-value if it's created with dict(key=key, key2=None)

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

No branches or pull requests

1 participant