Skip to content

Commit bedfb5c

Browse files
Verfied generated python code, atleast for smaller ret-counts.
1 parent 6461be4 commit bedfb5c

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

bind/gen_func.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,11 @@ func (g *pyGen) genFuncSig(sym *symbol, fsym *Func) bool {
200200
}
201201

202202
if len(goArgs) > 0 {
203-
gstr := strings.Join(goArgs, ", ")
204-
g.gofile.Printf("%v) %v", gstr, goRet)
203+
g.gofile.Printf("%v) %v", strings.Join(goArgs, ", "), goRet)
205204

206-
pstr := strings.Join(pyArgs, ", ")
207-
g.pybuild.Printf(", [%v])\n", pstr)
205+
g.pybuild.Printf(", [%v])\n", strings.Join(pyArgs, ", "))
208206

209-
wstr := strings.Join(wpArgs, ", ")
210-
g.pywrap.Printf("%v)", wstr)
207+
g.pywrap.Printf("%v)", strings.Join(wpArgs, ", "))
211208

212209
} else {
213210
g.gofile.Printf(") %v", goRet)
@@ -254,9 +251,6 @@ func (g *pyGen) genFuncBody(sym *symbol, fsym *Func) {
254251

255252
pkgname := g.cfg.Name
256253

257-
_, gdoc, _ := extractPythonName(fsym.GoName(), fsym.Doc())
258-
ifchandle, gdoc := isIfaceHandle(gdoc)
259-
260254
sig := fsym.Signature()
261255
res := sig.Results()
262256
args := sig.Params()
@@ -271,6 +265,9 @@ func (g *pyGen) genFuncBody(sym *symbol, fsym *Func) {
271265
}
272266
}
273267

268+
_, gdoc, _ := extractPythonName(fsym.GoName(), fsym.Doc())
269+
ifchandle, gdoc := isIfaceHandle(gdoc)
270+
274271
g.pywrap.Printf(":\n")
275272
g.pywrap.Indent()
276273
g.pywrap.Printf(`"""%s"""`, gdoc)
@@ -402,8 +399,9 @@ if __err != nil {
402399
g.pywrap.Printf(pyFuncCall)
403400
}
404401

405-
g.pywrap.Printf("\n\n")
402+
g.pywrap.Printf("\n")
406403
g.pywrap.Outdent()
404+
g.pywrap.Printf("\n")
407405

408406
goFuncCall := ""
409407
if isMethod {

bind/package.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,18 @@ func (p *Package) getDoc(parent string, o types.Object) string {
241241
}
242242

243243
params := parseFn(sig.Params())
244-
results := parseFn(sig.Results())
244+
245+
res := sig.Results()
246+
results := parseFn(res)
247+
248+
if (len(results) > 0) {
249+
lastResult := res.At(len(results)-1)
250+
if isErrorType(lastResult.Type()) {
251+
if !NoPyExceptions {
252+
results = results[0:len(results)-1]
253+
}
254+
}
255+
}
245256

246257
paramString := strings.Join(params, ", ")
247258
resultString := strings.Join(results, ", ")

0 commit comments

Comments
 (0)