From d6b2e459e09949f55a9d51f912dde954fe42f256 Mon Sep 17 00:00:00 2001 From: IanCa Date: Thu, 10 Aug 2023 18:28:07 -0500 Subject: [PATCH] Minor code simplifications --- hed/schema/hed_schema_io.py | 4 ++-- hed/schema/schema_io/wiki2schema.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hed/schema/hed_schema_io.py b/hed/schema/hed_schema_io.py index 11980ed47..600f1dbad 100644 --- a/hed/schema/hed_schema_io.py +++ b/hed/schema/hed_schema_io.py @@ -173,9 +173,9 @@ def load_schema_version(xml_version=None, xml_folder=None): - The xml_version is not valid. - A fatal error was encountered in parsing """ + # Check if we start and end with a square bracket, or double quote. This might be valid json if xml_version and isinstance(xml_version, str) and \ - ((xml_version.startswith("[") and xml_version.endswith("]")) or - (xml_version.startswith('"') and xml_version.endswith('"'))): + ((xml_version[0], xml_version[-1]) in [('[', ']'), ('"', '"')]): try: xml_version = json.loads(xml_version) except json.decoder.JSONDecodeError as e: diff --git a/hed/schema/schema_io/wiki2schema.py b/hed/schema/schema_io/wiki2schema.py index 500181d55..a02f9ed6e 100644 --- a/hed/schema/schema_io/wiki2schema.py +++ b/hed/schema/schema_io/wiki2schema.py @@ -339,9 +339,9 @@ def _remove_nowiki_tag_from_line(self, line_number, tag_line): """ index1 = tag_line.find(no_wiki_start_tag) index2 = tag_line.find(no_wiki_end_tag) - if (index1 == -1 and index2 != -1) or (index2 == -1 and index1 != -1): + if index1 == -1 ^ index2 == -1: # XOR operation, true if exactly one of the conditions is true self._add_fatal_error(line_number, tag_line, "Invalid or non matching tags found") - elif index1 != -1 and index2 != -1 and index2 <= index1: + elif index1 != -1 and index2 <= index1: self._add_fatal_error(line_number, tag_line, " appears before on a line") tag_line = re.sub(no_wiki_tag, '', tag_line) return tag_line