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

OmegaConf doesn't properly support StrEnum #1182

Open
jeremyk opened this issue Jul 8, 2024 · 2 comments
Open

OmegaConf doesn't properly support StrEnum #1182

jeremyk opened this issue Jul 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@jeremyk
Copy link

jeremyk commented Jul 8, 2024

Describe the bug
In the example in the docs for Enums these all work:

>>> conf.height = Height.TALL
>>> assert conf.height == Height.TALL

>>> # The name of Height.TALL is TALL
>>> conf.height = "TALL"
>>> assert conf.height == Height.TALL

>>> # The ordinal of Height.TALL is 1
>>> conf.height = 1
>>> assert conf.height == Height.TALL

but for Str enums (same as docs but use StrEnum instead):

from enum import StrEnum
class Height(StrEnum):
    SHORT = "short"
    TALL = "tall"

The first two examples work as with regular enums but the third:

>>> conf.height = "tall"

gives: omegaconf.errors.ValidationError: Invalid value 'tall', expected one of [SHORT, TALL]

To Reproduce
See description

Expected behavior
You would be able to set a StrEnum with the key or the value.

Additional context

  • [latest ] OmegaConf version: <FILL>
  • [3.11+ ] Python version: <FILL>
  • [any] Operating system: <FILL>
  • [ x] Please provide a minimal repro
@jeremyk jeremyk added the bug Something isn't working label Jul 8, 2024
@jeremyk
Copy link
Author

jeremyk commented Jul 8, 2024

One more note - this is an issue for us as when we write out the config it will use the value ("tall" in this case) but that same config can't be read back in as it will throw the above error.

@omry
Copy link
Owner

omry commented Jul 15, 2024

Feel free to suggest patch to fix it (with tests).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants