Closed
Description
False positive for used-before-assignment
from subscript notation in comprehension followed by definition of that same variable later in an except block.
# test.py
def select_dict(data, keys):
try:
d = {key: data[key] for key in keys}
except KeyError as e:
key, *_ = e.args
raise Exception(f"{key} not found")
return d
$ pip install -U pylint==2.13.4 -q && pylint test.py
************* Module test
test.py:3:23: E0601: Using variable 'key' before assignment (used-before-assignment)
------------------------------------------------------------------
Your code has been rated at 2.86/10 (previous run: 2.86/10, +0.00)
Originally posted by @skshetry in #6035 (comment)
Activity