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

Add support for base class for enums #1313

Open
rezondrey opened this issue May 11, 2023 · 1 comment
Open

Add support for base class for enums #1313

rezondrey opened this issue May 11, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@rezondrey
Copy link

rezondrey commented May 11, 2023

Is your feature request related to a problem? Please describe.

Python 3.11 has introduced some breaking changes for enums when used in f-strings.

class MyEnum(str, Enum):
    VALUE = "value"

# Prior python 3.11:    
print(f'{MyEnum.VALUE}')
    # => "value"
# Since python 3.11:
print(f'{MyEnum.VALUE}')
    # => "MyEnum.VALUE"

This behavior is different when using the new StrEnum:

 from enum import StrEnum

class MyEnum(StrEnum):
    VALUE = "value"
    
# Python 3.11:
print(f'{MyEnum.VALUE}')
    # => "value"

This blog describes the problem:
https://blog.pecar.me/python-enum

Describe the solution you'd like
Add support for additional argument, or extend "--use-subclass-enum" to allow choosing between (str, Enum) and StrEnum

Or maybe even allow selecting base class for enums, for people using custom enum packages such as https://pypi.org/project/StrEnum/

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@GeorgeFischhof
Copy link

Hi,
I installed version 0.25.8 and found the same: datamodel-code-generator creates classes from (str, Enum) instead of StrEnum

BR,
George

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants