From a9530f26b0a7874b019fe8420f50a1dc16b37395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Kr=C3=B6ker?= Date: Wed, 29 Mar 2023 17:57:25 +0200 Subject: [PATCH] simplify index seek end condition --- dictdatabase/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dictdatabase/utils.py b/dictdatabase/utils.py index 757e4d0..b40586d 100644 --- a/dictdatabase/utils.py +++ b/dictdatabase/utils.py @@ -90,9 +90,12 @@ def seek_index_through_value_bytes(json_bytes: bytes, index: int) -> int: dict_depth -= 1 if dict_depth <= 0 and list_depth == 0: return i + 1 + dict_depth # dict_depth is -1 in case: {"a": {}} - elif list_depth == 0 and ((dict_depth == 0 and (current == byte_codes.COMMA or current == byte_codes.NEWLINE)) or dict_depth == -1): - # Handle commas and newline as exit points - return i + elif list_depth == 0: + if dict_depth == -1: + return i + if dict_depth == 0 and current in [byte_codes.COMMA, byte_codes.NEWLINE]: + # Handle commas and newline as exit points + return i i += 1 raise TypeError("Invalid JSON")