diff --git a/delimited/container.py b/delimited/container.py index ea4612b..7169e8b 100644 --- a/delimited/container.py +++ b/delimited/container.py @@ -102,7 +102,8 @@ def _unwrap(self, data): def unwrap(self): return self._unwrap(self) - def _access_handler(self, haystack, segment, path, i, kwargs={}): + # def _access_handler(self, haystack, segment, path, i, default=None, _update_function=None, _update_kwargs=None): + def _access_handler(self, haystack, segment, path, i, default=None): return haystack[segment], None def _access(self, path=None, create=False, _update_function=None, _update_kwargs={}): @@ -139,13 +140,22 @@ def _access(self, path=None, create=False, _update_function=None, _update_kwargs else: function = self._access_handler - kwargs.update({ - "kwargs": { - "create": create, - "_update_function": _update_function, - "_update_kwargs": _update_kwargs - } - }) + + # create closure for default method that access handler + # should call if no special logic applied + def default(**kwargs): + return haystack[segment], None + + # return self._access_handler_no_override(**{ + # "haystack": haystack, + # "segment": s, + # "path": path, + # "i": i, + # "_update_function": _update_function, + # "_update_kwargs": _update_kwargs + # }) + + kwargs.update({"default": default}) haystack, status = function(**kwargs) diff --git a/test/test_mapping.py b/test/test_mapping.py index 6a4862f..093de9d 100644 --- a/test/test_mapping.py +++ b/test/test_mapping.py @@ -223,21 +223,33 @@ def test_ref__subclassing(self): class Foo(NestedDict): - def _access_handler(self, haystack, segment, path, i, kwargs): + def _access_handler(self, haystack, segment, path, i, default): - if isinstance(haystack[segment], Foo): + if isinstance(haystack[segment], Foo): model = haystack[segment] haystack = model.get(path.after(i)) status = {"child": True} raise StopPathIteration(haystack, status) - return super()._access_handler(haystack, segment, path, i) + return default() child = Foo({"k": "v"}) parent = Foo({"child": child}) value = parent.get("child") - + + def test_ref__subclassing2(self): + + class Foo(NestedDict): + + def _access_handler(self, haystack, segment, path, i, default): + return default() + + child = Foo({"k": "v"}) + parent = Foo({"child": child}) + + parent.get("child") + # get def test_get__string_arg__returns_value(self):