From be61bd54de9fe27419cbfdc87b567775e9a2df87 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 28 Oct 2024 23:12:59 +0100 Subject: [PATCH] [pylint] Fix 'possibly-used-before-assignment' --- survey/management/survey_command.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/survey/management/survey_command.py b/survey/management/survey_command.py index b681e9cf..35642b77 100755 --- a/survey/management/survey_command.py +++ b/survey/management/survey_command.py @@ -28,16 +28,17 @@ def add_arguments(self, parser): def raise_value_error(error_type, value): """Raise a ValueError with a clean error message in python 2.7 and 3. :param string value: the attempted value.""" + valid_texts = [] + base = "--question-id {} / --question-text '{}'\n" if error_type in ["question-id", "question-text"]: - base = "--question-id {} / --question-text '{}'\n" - valids = [(q.pk, q.text) for q in Question.objects.all()] + valid_texts = [(q.pk, q.text) for q in Question.objects.all()] elif error_type in ["survey-name", "survey-id"]: base = "--survey-id {} / --survey-name '{}'\n" - valids = [(s.pk, s.name) for s in Survey.objects.all()] + valid_texts = [(s.pk, s.name) for s in Survey.objects.all()] msg = f"You tried to get --{error_type} '{value}' " - if valids: + if valid_texts: msg += "but is does not exists. Possibles values :\n" - for primary_key, name in valids: + for primary_key, name in valid_texts: msg += base.format(primary_key, name) msg = msg[:-1] # Remove last \n else: