Skip to content

Commit fcba594

Browse files
author
Randall C. O'Reilly
committed
fix for getting doc string for functions that return a type defined in the package: the doc is found under the type.. fixes missing gopy:interface=handle comment for such functions.
1 parent f802d38 commit fcba594

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

bind/gen_func.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (g *pyGen) genMethod(s *symbol, o *Func) {
220220
}
221221

222222
func isIfaceHandle(gdoc string) (bool, string) {
223-
const PythonIface = "\ngopy:interface=handle"
223+
const PythonIface = "gopy:interface=handle"
224224
if idx := strings.Index(gdoc, PythonIface); idx >= 0 {
225225
gdoc = gdoc[:idx] + gdoc[idx+len(PythonIface)+1:]
226226
return true, gdoc

bind/package.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func (p *Package) getDoc(parent string, o types.Object) string {
132132
if err != nil {
133133
return ""
134134
}
135+
135136
doc := func() string {
136137
if o.Parent() == nil || (o.Parent() != nil && parent != "") {
137138
for _, typ := range p.doc.Types {
@@ -162,6 +163,28 @@ func (p *Package) getDoc(parent string, o types.Object) string {
162163
return ""
163164
}()
164165

166+
// if a function returns a type defined in the package,
167+
// it is organized under that type
168+
if doc == "" && sig.Results().Len() == 1 {
169+
ret := sig.Results().At(0).Type()
170+
if ntyp, ok := ret.(*types.Named); ok {
171+
tn := ntyp.Obj().Name()
172+
doc = func() string {
173+
for _, typ := range p.doc.Types {
174+
if typ.Name != tn {
175+
continue
176+
}
177+
for _, m := range typ.Funcs {
178+
if m.Name == n {
179+
return m.Doc
180+
}
181+
}
182+
}
183+
return ""
184+
}()
185+
}
186+
}
187+
165188
parseFn := func(tup *types.Tuple) []string {
166189
params := []string{}
167190
if tup == nil {

0 commit comments

Comments
 (0)