MCPcopy Create free account
hub / github.com/go-python/gopy / genFuncSig

Method genFuncSig

bind/gen_func.go:38–196  ·  view source on GitHub ↗

genFuncSig generates just the signature for binding returns false if function is not suitable for python binding (e.g., multiple return values)

(sym *symbol, fsym *Func)

Source from the content-addressed store, hash-verified

36// returns false if function is not suitable for python
37// binding (e.g., multiple return values)
38func (g *pyGen) genFuncSig(sym *symbol, fsym *Func) bool {
39 isMethod := (sym != nil)
40
41 if fsym.sig == nil {
42 return false
43 }
44
45 gname := fsym.GoName()
46 if g.cfg.RenameCase {
47 gname = toSnakeCase(gname)
48 }
49
50 gname, gdoc, err := extractPythonName(gname, fsym.Doc())
51 if err != nil {
52 return false
53 }
54 ifchandle, gdoc := isIfaceHandle(gdoc)
55
56 sig := fsym.sig
57 args := sig.Params()
58 res := sig.Results()
59 nargs := 0
60 nres := len(res)
61
62 // note: this is enforced in creation of Func, in newFuncFrom
63 if nres > 2 {
64 return false
65 }
66 if nres == 2 && !fsym.err {
67 return false
68 }
69
70 var (
71 goArgs []string
72 pyArgs []string
73 wpArgs []string
74 )
75
76 if isMethod {
77 goArgs = append(goArgs, "_handle CGoHandle")
78 pyArgs = append(pyArgs, fmt.Sprintf("param('%s', '_handle')", PyHandle))
79 wpArgs = append(wpArgs, "self")
80 }
81
82 nargs = len(args)
83 for i := 0; i < nargs; i++ {
84 arg := args[i]
85 sarg := current.symtype(arg.GoType())
86 if sarg == nil {
87 return false
88 }
89 anm := pySafeArg(arg.Name(), i)
90
91 if ifchandle && arg.sym.goname == "interface{}" {
92 goArgs = append(goArgs, fmt.Sprintf("%s %s", anm, CGoHandle))
93 pyArgs = append(pyArgs, fmt.Sprintf("param('%s', '%s')", PyHandle, anm))
94 } else {
95 goArgs = append(goArgs, fmt.Sprintf("%s %s", anm, sarg.cgoname))

Callers 2

genFuncMethod · 0.95
genMethodMethod · 0.95

Calls 13

toSnakeCaseFunction · 0.85
extractPythonNameFunction · 0.85
isIfaceHandleFunction · 0.85
pySafeArgFunction · 0.85
ParamsMethod · 0.80
ResultsMethod · 0.80
symtypeMethod · 0.80
PrintfMethod · 0.80
GoNameMethod · 0.65
DocMethod · 0.65
GoTypeMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected