File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ type Config struct {
77 Package string `json:"package"`
88 Out string `json:"out"`
99 EmitPydanticModels bool `json:"emit_pydantic_models"`
10+ EmitStrEnum bool `json:"emit_str_enum"`
1011 QueryParameterLimit * int32 `json:"query_parameter_limit"`
1112 InflectionExcludeTableNames []string `json:"inflection_exclude_table_names"`
1213}
Original file line number Diff line number Diff line change @@ -681,12 +681,19 @@ func buildModelsTree(ctx *pyTmplCtx, i *importer) *pyast.Node {
681681 mod .Body = append (mod .Body , buildImportGroup (std ), buildImportGroup (pkg ))
682682
683683 for _ , e := range ctx .Enums {
684+ bases := []* pyast.Node {
685+ poet .Name ("str" ),
686+ poet .Attribute (poet .Name ("enum" ), "Enum" ),
687+ }
688+ if i .C .EmitStrEnum {
689+ // override the bases to emit enum.StrEnum (only support in Python >=3.11)
690+ bases = []* pyast.Node {
691+ poet .Attribute (poet .Name ("enum" ), "StrEnum" ),
692+ }
693+ }
684694 def := & pyast.ClassDef {
685- Name : e .Name ,
686- Bases : []* pyast.Node {
687- poet .Name ("str" ),
688- poet .Attribute (poet .Name ("enum" ), "Enum" ),
689- },
695+ Name : e .Name ,
696+ Bases : bases ,
690697 }
691698 if e .Comment != "" {
692699 def .Body = append (def .Body , & pyast.Node {
You can’t perform that action at this time.
0 commit comments