MCPcopy Index your code
hub / github.com/go-python/gopy / genIfaceInit

Method genIfaceInit

bind/gen_struct.go:318–352  ·  view source on GitHub ↗
(ifc *Interface)

Source from the content-addressed store, hash-verified

316}
317
318func (g *pyGen) genIfaceInit(ifc *Interface) {
319 g.pywrap.Printf("def __init__(self, *args, **kwargs):\n")
320 g.pywrap.Indent()
321 g.pywrap.Printf(`"""
322handle=A Go-side object is always initialized with an explicit handle=arg
323"""
324`)
325
326 g.pywrap.Printf("if len(kwargs) == 1 and 'handle' in kwargs:\n")
327 g.pywrap.Indent()
328 g.pywrap.Printf("self.handle = kwargs['handle']\n")
329 g.pywrap.Printf("_%s.IncRef(self.handle)\n", g.pypkgname)
330 g.pywrap.Outdent()
331 g.pywrap.Printf("elif len(args) == 1 and isinstance(args[0], go.GoClass):\n")
332 g.pywrap.Indent()
333 g.pywrap.Printf("self.handle = args[0].handle\n")
334 g.pywrap.Printf("_%s.IncRef(self.handle)\n", g.pypkgname)
335 g.pywrap.Outdent()
336 g.pywrap.Printf("else:\n")
337 g.pywrap.Indent()
338 g.pywrap.Printf("self.handle = 0\n")
339 g.pywrap.Outdent()
340 g.pywrap.Outdent()
341
342 for _, m := range ifc.meths {
343 if !isStringer(m.obj) {
344 continue
345 }
346 g.pywrap.Printf("def __str__(self):\n")
347 g.pywrap.Indent()
348 g.genStringerCall()
349 g.pywrap.Outdent()
350 g.pywrap.Printf("\n")
351 }
352}
353
354func (g *pyGen) genIfaceMethods(ifc *Interface) {
355 for _, m := range ifc.meths {

Callers 1

genInterfaceMethod · 0.95

Calls 5

genStringerCallMethod · 0.95
isStringerFunction · 0.85
PrintfMethod · 0.80
IndentMethod · 0.80
OutdentMethod · 0.80

Tested by

no test coverage detected