From be98c9b7f6c67e23ea101223934d67bba512e645 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 2 Feb 2022 15:59:12 -0800 Subject: [PATCH] simplify try/except by moving outside for loop --- jc/parsers/foo_s.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/jc/parsers/foo_s.py b/jc/parsers/foo_s.py index 25eef6c3..de5194d9 100644 --- a/jc/parsers/foo_s.py +++ b/jc/parsers/foo_s.py @@ -119,10 +119,11 @@ def parse( """ jc.utils.compatibility(__name__, info.compatible, quiet) jc.utils.streaming_input_type_check(data) + line = '' - for line in data: - output_line: Dict = {} - try: + try: + for line in data: + output_line: Dict = {} jc.utils.streaming_line_input_type_check(line) # parse the content here @@ -134,5 +135,5 @@ def parse( else: raise ParseError('Not foo data') - except Exception as e: - yield stream_error(e, ignore_exceptions, line) + except Exception as e: + yield stream_error(e, ignore_exceptions, line)