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 snakecase conversion for struct fields in genStructInit #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions bind/gen_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ in which case a new Go object is constructed first
if _, err := isPyCompatField(f); err != nil {
continue
}

gname := f.Name()
if g.cfg.RenameCase {
gname = toSnakeCase(gname)
}

if newName, err := extractPythonNameFieldTag(gname, s.Struct().Tag(i)); err == nil {
gname = newName
}

// NOTE: this will accept int args for any handles / object fields so
// some kind of additional type-checking logic to prevent that in a way
// that also allows valid handles to be used as required. This is
Expand All @@ -79,11 +89,11 @@ in which case a new Go object is constructed first
// etc can be assigned to directly.
g.pywrap.Printf("if %[1]d < len(args):\n", i)
g.pywrap.Indent()
g.pywrap.Printf("self.%s = args[%d]\n", f.Name(), i)
g.pywrap.Printf("self.%s = args[%d]\n", gname, i)
g.pywrap.Outdent()
g.pywrap.Printf("if %[1]q in kwargs:\n", f.Name())
g.pywrap.Printf("if %[1]q in kwargs:\n", gname)
g.pywrap.Indent()
g.pywrap.Printf("self.%[1]s = kwargs[%[1]q]\n", f.Name())
g.pywrap.Printf("self.%[1]s = kwargs[%[1]q]\n", gname)
g.pywrap.Outdent()
}
g.pywrap.Outdent()
Expand Down