From c0990473c5adda26520b309963d78189f11a487a Mon Sep 17 00:00:00 2001 From: Cariad Eccleston Date: Tue, 19 Dec 2023 16:54:57 +0000 Subject: [PATCH] Yield None when resolving any value from a None record (#38) --- rolumns/data_resolver.py | 9 +++++++++ tests/test_data_resolver.py | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/rolumns/data_resolver.py b/rolumns/data_resolver.py index 8c64f18..59efb77 100644 --- a/rolumns/data_resolver.py +++ b/rolumns/data_resolver.py @@ -19,6 +19,15 @@ def __init__(self, root: Any) -> None: @staticmethod def _resolve(parts: List[str], data: Any) -> Iterable[Optional[Any]]: + if data is None: + logger.warning( + "Cannot use %s as indices of None, so yielding None", + parts, + ) + + yield None + return + if isinstance(data, list): for d in data: for r in DataResolver._resolve(parts.copy(), d): diff --git a/tests/test_data_resolver.py b/tests/test_data_resolver.py index 39563fd..7cc650d 100644 --- a/tests/test_data_resolver.py +++ b/tests/test_data_resolver.py @@ -8,6 +8,13 @@ @mark.parametrize( "data, path, expect", [ + ( + None, + "name", + [ + None, + ], # There is no "name" in None. + ), ( {}, "name",