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

[BUG] python generated models for py3.11+ should use StrEnum instead of str,Enum #18995

Open
stdweird opened this issue Jun 21, 2024 · 3 comments

Comments

@stdweird
Copy link

Bug Report Checklist

As of python 3.11, a generate model class class MyType(str, Enum) should be replaced by class MyType(StrEnum)

Quite annoying, more info https://blog.pecar.me/python-enum

@wing328
Copy link
Member

wing328 commented Jun 22, 2024

how critical is it?

we still need to support older versions of python, e.g. 3.9 even though it's reached EOL

@wing328
Copy link
Member

wing328 commented Jun 22, 2024

one workaround is to use customized templates (e.g. -t via CLI)

@stdweird
Copy link
Author

@wing328 i was not suggesting to drop all older python versions. i am well aware that i spartically impossible.
the impact depends on how you use the enums in code: if you keep using the myenum.NAME.value, nothing changes, but if you use the enum stringifictaion, like f"{myenum.NAME}" (and expect the .value string) it is broken.

a solution might be to do something like

try:
    from enum import StrEnum
except:
    class StrEnum(str, Enum):
        ...

and use StrEnum in the generated code ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants