Ai
3 Star 0 Fork 0

mirrors_go-python/gpython

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
boundmethod.go 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
// BoundMethod object
//
// Combines an object and a callable
package py
// A python BoundMethod object
type BoundMethod struct {
Self Object
Method Object
}
var BoundMethodType = NewType("boundmethod", "boundmethod object")
// Type of this object
func (o *BoundMethod) Type() *Type {
return BoundMethodType
}
// Define a new boundmethod
func NewBoundMethod(self, method Object) *BoundMethod {
return &BoundMethod{Self: self, Method: method}
}
// Call the bound method
func (bm *BoundMethod) M__call__(args Tuple, kwargs StringDict) (Object, error) {
// Call built in methods slightly differently
// FIXME not sure this is sensible! something is wrong with the call interface
// as we aren't sure whether to call it with a self or not
if m, ok := bm.Method.(*Method); ok {
if kwargs != nil {
return m.CallWithKeywords(bm.Self, args, kwargs)
} else {
return m.Call(bm.Self, args)
}
}
newArgs := make(Tuple, len(args)+1)
newArgs[0] = bm.Self
copy(newArgs[1:], args)
return Call(bm.Method, newArgs, kwargs)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_go-python/gpython.git
git@gitee.com:mirrors_go-python/gpython.git
mirrors_go-python
gpython
gpython
v0.0.1

搜索帮助