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

Allow us to specify which fields use Literals and which ones use Enums #2154

Open
nbro10 opened this issue Nov 7, 2024 · 0 comments
Open

Comments

@nbro10
Copy link
Contributor

nbro10 commented Nov 7, 2024

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

In most cases, I prefer to use Enums, because it's easier to inspect the enum values than inspecting the literals, as far as I know. So, I usually generate the code using enums. However, for a specific field of a model, I think I need to use a Literal, because this generated class is supposed to be the base class of other classes, which I may manually define, and inheritance doesn't work with enums, as far as I know.

To be concrete, let's say I have a generated class like this

class ALanguage(Enum):
    EN = "en"
    FR = "fr"
    ES = "es"
    ...

class A
    language: ALanguage 
    ...

Now, let's say I define

class BLanguage(Enum):
    EN = "en"

class B(A)
    language: BLanguage
    ...

I think this would be wrong inheritance because BLanguage doesn't inherit from ALanguage and even if I changed the code so that BLanguage(ALanguage), I think it's not allowed to redefine the enum options in enum subclasses. I want to restrict the languages in B, and ALanguage should be as general as possible, i.e. contain all possible languages, but I don't think this is possible with Enums because I don't think I can restrict the languages in BLanguage. So, in this specific case, I think Literal would be better, although I am also not sure how inheritance would work with literals, but I think it's allowed to restrict the possible values of the literal in subclasses.

Describe the solution you'd like

A way to specify that we want a specific field of a specific class to use literals instead of enums. For example, using a command-line parameter.

Describe alternatives you've considered

The current alternative is just to manually edit A after it's been generated, but this a pain

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

No branches or pull requests

1 participant