mirror of https://github.com/go-python/gopy.git
bind/utils: helper to check wether a func is 'func String() string'
This commit is contained in:
parent
0058490f51
commit
a083052bf6
|
@ -11,3 +11,35 @@ import (
|
|||
func isErrorType(typ types.Type) bool {
|
||||
return typ == types.Universe.Lookup("error").Type()
|
||||
}
|
||||
|
||||
func isStringer(obj types.Object) bool {
|
||||
switch obj := obj.(type) {
|
||||
case *types.Func:
|
||||
if obj.Name() != "String" {
|
||||
return false
|
||||
}
|
||||
sig, ok := obj.Type().(*types.Signature)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if sig.Recv() == nil {
|
||||
return false
|
||||
}
|
||||
if sig.Params().Len() != 0 {
|
||||
return false
|
||||
}
|
||||
res := sig.Results()
|
||||
if res.Len() != 1 {
|
||||
return false
|
||||
}
|
||||
ret := res.At(0).Type()
|
||||
if ret != types.Universe.Lookup("string").Type() {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue