diff --git a/bind/gen_varconst.go b/bind/gen_varconst.go index e0906a5..f794af8 100644 --- a/bind/gen_varconst.go +++ b/bind/gen_varconst.go @@ -125,6 +125,16 @@ func (g *pyGen) genConstValue(c *Const) { val = "False" } g.pywrap.Printf("%s = %s\n", c.GoName(), val) + if c.doc != "" { + lns := strings.Split(c.doc, "\n") + g.pywrap.Printf(`"""`) + g.pywrap.Printf("\n") + for _, l := range lns { + g.pywrap.Printf("%s\n", l) + } + g.pywrap.Printf(`"""`) + g.pywrap.Printf("\n") + } } func (g *pyGen) genEnum(e *Enum) { diff --git a/bind/package.go b/bind/package.go index 8a87df5..2136abb 100644 --- a/bind/package.go +++ b/bind/package.go @@ -112,6 +112,7 @@ func (p *Package) getDoc(parent string, o types.Object) string { n := o.Name() switch tp := o.(type) { case *types.Const: + // Check for untyped consts for _, c := range p.doc.Consts { for _, cn := range c.Names { if n == cn { @@ -119,6 +120,26 @@ func (p *Package) getDoc(parent string, o types.Object) string { } } } + // Check for typed consts + scopeName := p.pkg.Scope().Lookup(n) + if scopeName == nil { + return "" + } + constType := scopeName.Type() + if constType == nil { + return "" + } + for _, t := range p.doc.Types { + if p.pkg.Path()+"."+t.Name == constType.String() { + for _, c := range t.Consts { + for _, cn := range c.Names { + if n == cn { + return c.Doc + } + } + } + } + } case *types.Var: if tp.IsField() && parent != "" {