Globally disable Pylint E0606 possibly-used-before-assignment rule + fix one case #1349
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As noted in #1098 (comment), the latest v3.2.0 Pylint release adds a new check
possibly-used-before-assignment / E0606
which checks for possible usages of variables before they are assigned to. This however currently seems to be throwing up a lot of false positives when running checks on main:Of these the only one I think is potentially valid is
src/tlo/analysis/hsi_events.py:498:39: E0606: Possibly using variable 'json_hsi_event_details' before assignment (possibly-used-before-assignment)
as inTLOmodel/src/tlo/analysis/hsi_events.py
Lines 468 to 499 in b844efe
if
args.json_file is None
andargs.merge_json_details
isTrue
then line 498 will be run andjson_hsi_event_details
will not be defined (this set of arguments would not in itself make sense but we should probably still have a more informative error message triggered if these arguments are encountered).The other cases I think are all false positives, corresponding to variants of the following minimum working examples
with Pylint flagging E0606 failures on all four
case_*
functions even though I think in all cases it is not possible for code path with an undefined variable to be reached. There are already a couple of open issues on Pylint repository pylint-dev/pylint/issues/9628 and pylint-dev/pylint/issues/9627 with regards to false positives with E0606, and I think some of above cases may suggest there are further things needing fixing to make this check robust.This PR therefore globally disables the Pylint E0606 rule by adding to the
tool.pylint.main.disable
list. It also adds logic to raise an exception with a more informative error message for the true positive identified inhsi_events.py
with regards tojson_hsi_event_details
potentially not being defined when used for some (invalid) argument values, though because of I think pylint-dev/pylint/issues/9627 a false positive E0606 violation is still registered after this fix.