From 1fd0492104e310d01b6192af1712f518e161f57a Mon Sep 17 00:00:00 2001 From: Takeshi Ikuma Date: Wed, 24 Feb 2021 19:45:14 -0600 Subject: [PATCH] case-insensitive-enums --- src/utils/pybind11/ImplicitStringToEnumConversion.h | 5 +++-- tests/test_enums.py | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/test_enums.py diff --git a/src/utils/pybind11/ImplicitStringToEnumConversion.h b/src/utils/pybind11/ImplicitStringToEnumConversion.h index 29813821..84371f79 100644 --- a/src/utils/pybind11/ImplicitStringToEnumConversion.h +++ b/src/utils/pybind11/ImplicitStringToEnumConversion.h @@ -31,8 +31,9 @@ void make_implicitly_convertible_from_string(pybind11::enum_ &enumType) enumType.def(pybind11::init([enumType](pybind11::str value) { auto values = pybind11::dict(enumType.attr("__members__")); - if (values.contains(value)) { - return pybind11::cast(values[value]); + auto key = value.attr("upper")(); + if (values.contains(key)) { + return pybind11::cast(values[key]); } throw pybind11::value_error("\"" + pybind11::cast(value) + "\" is not a valid value for enum type " + pybind11::cast(enumType.attr("__name__"))); diff --git a/tests/test_enums.py b/tests/test_enums.py new file mode 100644 index 00000000..fe3305e7 --- /dev/null +++ b/tests/test_enums.py @@ -0,0 +1,7 @@ +import numpy as np +import parselmouth as pm + +def test_case(sound): + pitch = sound.to_pitch("CC") + pitch = sound.to_pitch("cc") + \ No newline at end of file