There is disable-possibly-unused-variable
now (since pylint 2.0 was released on 2018-07-15), which one could ignore in files importing your say
module:
New possibly-unused-variable check added.
This is similar to unused-variable, the only difference is that it is emitted when we detect a locals() call in the scope of the unused variable. The locals() call could potentially use the said variable, by consuming all values that are present up to the point of the call. This new check allows to disable this error when the user intentionally uses locals() to consume everything.
For instance, the following code will now trigger this new error:
def func():
some_value = some_call()
return locals()
The rationale for this check explicitly includes your use case, though it's noted that it's not a perfect solution:
It would be great to have a separate check for unused variables if locals() is used in the same scope:
def example_no_locals():
value = 42 # pylint: disable=unused-variable
def exmaple_defined_before():
value = 42 # pylint: disable=possibly-unused-variable
print(locals())
def exmaple_defined_after():
print(locals())
value = 42 # pylint: disable=unused-variable
The benefit of this is that one can disable probably-unused-variable for a file (that has a lot of string formatting in it, or the config code example in #641) or the whole project without also loosing checks for unused-variable.