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

Function extractPythonNameFieldTag

bind/utils.go:274–287  ·  view source on GitHub ↗

extractPythonNameFieldTag parses a struct field tag and returns a new python name. If the tag is not defined then the original name is returned. If the tag name is specified but is an invalid python identifier, then an error is returned.

(gname, tag string)

Source from the content-addressed store, hash-verified

272// If the tag name is specified but is an invalid python identifier,
273// then an error is returned.
274func extractPythonNameFieldTag(gname, tag string) (string, error) {
275 const tagKey = "gopy"
276 if tag == "" {
277 return gname, nil
278 }
279 tagVal := reflect.StructTag(tag).Get(tagKey)
280 if tagVal == "" {
281 return gname, nil
282 }
283 if !isValidPythonName(tagVal) {
284 return "", fmt.Errorf("gopy: invalid identifier for struct field tag: %s", tagVal)
285 }
286 return tagVal, nil
287}
288
289// isValidPythonName returns true if the string is a valid
290// python identifier name

Callers 2

genStructMemberGetterMethod · 0.85
genStructMemberSetterMethod · 0.85

Calls 1

isValidPythonNameFunction · 0.85

Tested by

no test coverage detected