From 9e657effe5399324fbcf7149cf7fb342fd723482 Mon Sep 17 00:00:00 2001 From: B13nch3n <b13nch3n_01@theb-si.de> Date: Thu, 15 Feb 2024 15:02:15 +0100 Subject: [PATCH] Starting walrus operator --- validation/validate-mmcif-file.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/validation/validate-mmcif-file.py b/validation/validate-mmcif-file.py index db01afd..7f18e1f 100755 --- a/validation/validate-mmcif-file.py +++ b/validation/validate-mmcif-file.py @@ -820,19 +820,21 @@ class _CifCheck: ) continue # Invalid value - match = re.match( + for pttrn in [ r"^ERROR - In block \"(?P<dblock>.*)\", mandatory item " + r"\"(?P<itm>.*)\" has invalid value (?P<vle>.*) in row: " + r"\".*\" == \"\d+\"$", - line, - ) + ]: + if (match := re.match(pttrn, line)) is not None: + # ToDo: use the walrus operator := everywhere here + rprt["Invalid values"].add( + f'{match.group("itm")}={match.group("vle")}' + ) + if "dblock" in match.groupdict(): + _check_dblock_name(match.group("dblock"), rprt) + break if match is not None: - rprt["Invalid values"].add( - f'{match.group("itm")}={match.group("vle")}' - ) - _check_dblock_name(match.group("dblock"), rprt) continue - # Unmatched lines need to be added to above evaluation raise RuntimeError( f'Unmatched diagnosis line found:\n"""{line}"""' -- GitLab