Closed agkphysics closed 1 year ago
if it raises a
KeyError
So as for the case where there's both an enum key and an enum value that match:
class Val(Enum):
A = "B"
B = "C"
In this case, merge(config, create({"val": "B"}))
would give {"val": Val.B}
, not {"val": Val.A}
.
In some cases, this would be a breaking change. Not sure this is a big enough problem to justify a fix. Per Python docs, the majority of Python enums are using integer values.
Yeah, it's probably too much hassle for what it's worth and might cause other issues. There are other ways around the issue.
Is your feature request related to a problem? Please describe. When using strings as enum items, only the key is compared, not the value:
Describe the solution you'd like Using the string enum value instead of the key would be nice. In these lines, if it raises a
KeyError
, perhaps it could checkenum_type(value)
as well. It already does this ifvalue
is an integer. https://github.com/omry/omegaconf/blob/71f833b6046f0b514530ed791c57080287fa0bb0/omegaconf/nodes.py#L487-L491The main issue with this approach would be if the enum key->value mapping is not one-to-one. So it would need to be checked. Perhaps that's too impractical.
Additional context My particular use case was where the enum value began with a number, so the key had to begin with an underscore. So I had to specify the underscore in the config.