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

Method getDoc

bind/package.go:111–293  ·  view source on GitHub ↗

getDoc returns the doc string associated with types.Object parent is the name of the containing scope ("" for global scope)

(parent string, o types.Object)

Source from the content-addressed store, hash-verified

109// getDoc returns the doc string associated with types.Object
110// parent is the name of the containing scope ("" for global scope)
111func (p *Package) getDoc(parent string, o types.Object) string {
112 n := o.Name()
113 switch tp := o.(type) {
114 case *types.Const:
115 // Check for untyped consts
116 for _, c := range p.doc.Consts {
117 for _, cn := range c.Names {
118 if n == cn {
119 return c.Doc
120 }
121 }
122 }
123 // Check for typed consts
124 scopeName := p.pkg.Scope().Lookup(n)
125 if scopeName == nil {
126 return ""
127 }
128 constType := scopeName.Type()
129 if constType == nil {
130 return ""
131 }
132 for _, t := range p.doc.Types {
133 if p.pkg.Path()+"."+t.Name == constType.String() {
134 for _, c := range t.Consts {
135 for _, cn := range c.Names {
136 if n == cn {
137 return c.Doc
138 }
139 }
140 }
141 }
142 }
143
144 case *types.Var:
145 if tp.IsField() && parent != "" {
146 // Find the package-scoped struct
147 for _, typ := range p.doc.Types {
148 _ = typ
149 if typ.Name != parent {
150 continue
151 }
152 // Name matches package-scoped struct.
153 // Make sure it is a struct type.
154 for _, spec := range typ.Decl.Specs {
155 typSpec, ok := spec.(*ast.TypeSpec)
156 if !ok {
157 continue
158 }
159 structSpec, ok := typSpec.Type.(*ast.StructType)
160 if !ok {
161 continue
162 }
163 // We have the package-scoped struct matching the parent name.
164 // Find the matching field.
165 for _, field := range structSpec.Fields.List {
166 for _, fieldName := range field.Names {
167 if fieldName.Name == tp.Name() {
168 return field.Doc.Text()

Callers 10

processMethod · 0.95
newStructFunction · 0.80
newInterfaceFunction · 0.80
newSliceFunction · 0.80
newMapFunction · 0.80
newFuncFromFunction · 0.80
newConstFunction · 0.80
newEnumFunction · 0.80
newVarFromFunction · 0.80
genStructMemberGetterMethod · 0.80

Calls 9

isPyCompatFuncFunction · 0.85
LookupMethod · 0.80
ResultsMethod · 0.80
symtypeMethod · 0.80
ParamsMethod · 0.80
NameMethod · 0.45
StringMethod · 0.45
AtMethod · 0.45
ObjMethod · 0.45

Tested by

no test coverage detected