Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

case-insensitive-enums #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/utils/pybind11/ImplicitStringToEnumConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ void make_implicitly_convertible_from_string(pybind11::enum_<Type> &enumType)
enumType.def(pybind11::init([enumType](pybind11::str value)
{
auto values = pybind11::dict(enumType.attr("__members__"));
if (values.contains(value)) {
return pybind11::cast<Type>(values[value]);
auto key = value.attr("upper")();
if (values.contains(key)) {
return pybind11::cast<Type>(values[key]);
}

throw pybind11::value_error("\"" + pybind11::cast<std::string>(value) + "\" is not a valid value for enum type " + pybind11::cast<std::string>(enumType.attr("__name__")));
Expand Down
7 changes: 7 additions & 0 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
@@ -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")