From a1a5846e36060b5c0b84598be6cd379d9ae9bcef Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Sun, 11 Feb 2024 10:06:36 -0500 Subject: [PATCH 1/2] check key in annotations --- neo/core/baseneo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neo/core/baseneo.py b/neo/core/baseneo.py index 3bd49e5ca..632015bb3 100644 --- a/neo/core/baseneo.py +++ b/neo/core/baseneo.py @@ -45,7 +45,8 @@ def _check_annotations(value): if not issubclass(value.dtype.type, ALLOWED_ANNOTATION_TYPES): raise ValueError(f"Invalid annotation. NumPy arrays with dtype {value.dtype.type}" f"are not allowed") elif isinstance(value, dict): - for element in value.values(): + for key, element in value.items(): + _check_annotations(key) _check_annotations(element) elif isinstance(value, (list, tuple)): for element in value: From e2fd822dfd5d0390012a0746509fcf2cd507af72 Mon Sep 17 00:00:00 2001 From: zm711 <92116279+zm711@users.noreply.github.com> Date: Mon, 19 Feb 2024 06:22:47 -0500 Subject: [PATCH 2/2] check that keys are strings --- neo/core/baseneo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neo/core/baseneo.py b/neo/core/baseneo.py index 632015bb3..cc031b03e 100644 --- a/neo/core/baseneo.py +++ b/neo/core/baseneo.py @@ -46,7 +46,8 @@ def _check_annotations(value): raise ValueError(f"Invalid annotation. NumPy arrays with dtype {value.dtype.type}" f"are not allowed") elif isinstance(value, dict): for key, element in value.items(): - _check_annotations(key) + if not isinstance(key, str): + raise TypeError(f"Annotations keys must be strings not of type {type(key)}") _check_annotations(element) elif isinstance(value, (list, tuple)): for element in value: