From dcc5acb7ff0d528e611d3044f078696b66a76035 Mon Sep 17 00:00:00 2001 From: Lucas Dedieu Date: Mon, 16 Dec 2024 11:02:50 +0000 Subject: [PATCH] pre-commit --- confit/utils/xjson.py | 12 ++++++++---- tests/test_config_instance.py | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/confit/utils/xjson.py b/confit/utils/xjson.py index 5a089cd..f49f36a 100644 --- a/confit/utils/xjson.py +++ b/confit/utils/xjson.py @@ -257,6 +257,7 @@ def __init__(self, value: str): self.value = value super().__init__(f"Malformed value: {value!r}") + def loads(s: str): """ Load an extended JSON string into a python object. @@ -266,15 +267,18 @@ def loads(s: str): return XJsonTransformer(s).transform(_json_parser.parse(s)) except Exception: # Detect malformed strings with unmatched quotes - if (s.startswith("'") and not s.endswith("'")) or (s.startswith('"') and not s.endswith('"')): + if (s.startswith("'") and not s.endswith("'")) or ( + s.startswith('"') and not s.endswith('"') + ): raise MalformedValueError(s) - + # Detect suspicious malformed patterns if any(char in s for char in ",{}[]") and not s.startswith(("'", '"')): raise MalformedValueError(s) - + return s - + + def dumps(o: Any): """ Dump a python object into an extended JSON string. diff --git a/tests/test_config_instance.py b/tests/test_config_instance.py index 00c261e..34b879c 100644 --- a/tests/test_config_instance.py +++ b/tests/test_config_instance.py @@ -691,6 +691,8 @@ def test_very_long_yaml_config(): config = Config.from_yaml_str( """\ a: {} - """.format("x" * 4200) + """.format( + "x" * 4200 + ) ) assert config == {"a": "x" * 4200}