From f68cae3f1e8bd031ffb0f4b454058bdfbe8aea5a Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 13 Jan 2024 11:55:36 +0100 Subject: [PATCH] style: silence tryceratops warning TRY300 Consider moving this statement to an `else` block --- tests/test_cli.py | 3 ++- yamllint/rules/quoted_strings.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index bcdd000..34dbc5b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -60,9 +60,10 @@ def utf8_available(): try: locale.setlocale(locale.LC_ALL, 'C.UTF-8') locale.setlocale(locale.LC_ALL, (None, None)) - return True except locale.Error: # pragma: no cover return False + else: + return True def setUpModule(): diff --git a/yamllint/rules/quoted_strings.py b/yamllint/rules/quoted_strings.py index 5bfbd7a..b38f6ed 100644 --- a/yamllint/rules/quoted_strings.py +++ b/yamllint/rules/quoted_strings.py @@ -216,12 +216,13 @@ def _quotes_are_needed(string, is_inside_a_flow): loader.get_token() try: a, b = loader.get_token(), loader.get_token() + except yaml.scanner.ScannerError: + return True + else: if (isinstance(a, yaml.ScalarToken) and a.style is None and isinstance(b, yaml.BlockEndToken) and a.value == string): return False return True - except yaml.scanner.ScannerError: - return True def _has_quoted_quotes(token):