From 62aee6508a0eb96a285049e2c1b1b592a21c5347 Mon Sep 17 00:00:00 2001 From: Igor <100174039+kehrazy@users.noreply.github.com> Date: Mon, 10 Apr 2023 06:59:24 +0300 Subject: [PATCH 1/4] fixed a typo in `split_path` --- scalpl/scalpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalpl/scalpl.py b/scalpl/scalpl.py index 65ab02f..44eaaf9 100644 --- a/scalpl/scalpl.py +++ b/scalpl/scalpl.py @@ -61,7 +61,7 @@ def split_path(path: str, key_separator: str) -> TKeyList: "you can only provide integers to access list items." ) else: - raise ValueError(f"Key '{section}' is badly formated.") + raise ValueError(f"Key '{section}' is badly formatted.") return result From d0885e4f5bd75022b233e52ee2efd13b77733481 Mon Sep 17 00:00:00 2001 From: Igor <100174039+kehrazy@users.noreply.github.com> Date: Mon, 10 Apr 2023 07:03:59 +0300 Subject: [PATCH 2/4] fixed some typos, made the code less error-prone. --- scalpl/scalpl.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scalpl/scalpl.py b/scalpl/scalpl.py index 44eaaf9..1a2cd99 100644 --- a/scalpl/scalpl.py +++ b/scalpl/scalpl.py @@ -68,6 +68,8 @@ def split_path(path: str, key_separator: str) -> TKeyList: def traverse(data: dict, keys: List[Union[str, int]], original_path: str): value = data + #: unlikely, but `key` can be referenced before assignment. + key = None try: for key in keys: value = value[key] @@ -85,8 +87,8 @@ class Cut: """ Cut is a simple wrapper over the built-in dict class. - It enables the standard dict API to operate on nested dictionnaries - and cut accross list item by using dot-separated string keys. + It enables the standard dict API to operate on nested dictionaries + and cut across list item by using dot-separated string keys. ex: query = {...} # Any dict structure @@ -116,7 +118,7 @@ def __contains__(self, path: str) -> bool: return False try: - item[last_key] + _ = item[last_key] return True except (KeyError, IndexError): return False From 82caffee076716d075a4432fb115f44a42015983 Mon Sep 17 00:00:00 2001 From: Igor <100174039+kehrazy@users.noreply.github.com> Date: Mon, 10 Apr 2023 07:11:05 +0300 Subject: [PATCH 3/4] changed the logic of `__contains__` --- scalpl/scalpl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scalpl/scalpl.py b/scalpl/scalpl.py index 1a2cd99..a892d35 100644 --- a/scalpl/scalpl.py +++ b/scalpl/scalpl.py @@ -119,10 +119,11 @@ def __contains__(self, path: str) -> bool: try: _ = item[last_key] - return True except (KeyError, IndexError): return False + return True + def __delitem__(self, path: str) -> None: *keys, last_key = split_path(path, self.sep) item = traverse(data=self.data, keys=keys, original_path=path) From 3962560447de257a6f6efaa7ddafc4d9f3ea68cb Mon Sep 17 00:00:00 2001 From: Igor <100174039+kehrazy@users.noreply.github.com> Date: Mon, 10 Apr 2023 07:13:01 +0300 Subject: [PATCH 4/4] make Cut implicitly inherit an "object" --- scalpl/scalpl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalpl/scalpl.py b/scalpl/scalpl.py index a892d35..69aca83 100644 --- a/scalpl/scalpl.py +++ b/scalpl/scalpl.py @@ -83,7 +83,7 @@ def traverse(data: dict, keys: List[Union[str, int]], original_path: str): return value -class Cut: +class Cut(object): """ Cut is a simple wrapper over the built-in dict class.