Skip to content

Commit f350f01

Browse files
justinfxsbinet
authored andcommitted
bind: ensure enum.Enum is imported in generated code as needed
This fix removes the static import of enum.Enum that was added only to the exe preamble, and replaces it with a conditional import added to all generated packages, only if there is at least one enum to generate. The conditional import improves python2 legacy support where Enum is an external dependency that must be present.
1 parent 7bd7360 commit f350f01

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bind/gen.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ os.chdir(cwd)
250250
# %[2]s
251251
252252
import _%[1]s, collections
253-
from enum import Enum
254253
255254
# to use this code in your end-user python file, import it as follows:
256255
# from %[1]s import %[3]s
@@ -776,6 +775,10 @@ func (g *pyGen) genAll() {
776775
}
777776

778777
g.pywrap.Printf("\n\n#---- Enums from Go (collections of consts with same type) ---\n")
778+
// conditionally add Enum support because it is an external dependency in py2
779+
if len(g.pkg.enums) > 0 {
780+
g.pywrap.Printf("from enum import Enum\n\n")
781+
}
779782
for _, e := range g.pkg.enums {
780783
g.genEnum(e)
781784
}

0 commit comments

Comments
 (0)