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)
The following incorrectly results in
perflint_issue.py:6:15: W8201: Consider moving this expression outside of the loop. (loop-invariant-statement)
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 withdict(key=key, key2=None)