Open
Description
(Issue altered after the discussions up to #5838 (comment) to better reflect intention)
Problem description
Pylint will give unused-variable
/ W0612 when code assigns a variable that is never used, but this message will not appear if there was any usage of the variable in the past. However, in code, I'd consider it a code smell to assign an unused value to a variable, even if the variable was used before. Consider this code:
#! /usr/bin/env python3
# pylint: disable=missing-docstring
def some_func():
var = 3
print(var)
var = 4
# var is never used again. The last assignment thus could be removed.
In c++ code, clang-tidy would warn about the dead store.
Expected behavior
Initially, I had considered this to be a case for unused-variable
. As @jacobtylerwalls pointed out, the variable is technically used, so maybe it should be a different message.
************* Module test
test.py:6:4: W0612: Unused variable 'var' (unused-variable)
-------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 10.00/10, -3.33)
Pylint version
pylint 2.13.0-dev0
astroid 2.9.3
Python 3.9.7 (default, Sep 10 2021, 14:59:43) [GCC 11.2.0]
(installed from main at 6622d10)