Ai
3 Star 0 Fork 0

mirrors_go-python/gpython

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
staticmethod.go 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
// StaticMethod objects
package py
var StaticMethodType = ObjectType.NewType("staticmethod",
`staticmethod(function) -> method
Convert a function to be a static method.
A static method does not receive an implicit first argument.
To declare a static method, use this idiom:
class C:
def f(arg1, arg2, ...): ...
f = staticmethod(f)
It can be called either on the class (e.g. C.f()) or on an instance
(e.g. C().f()). The instance is ignored except for its class.
Static methods in Python are similar to those found in Java or C++.
For a more advanced concept, see the classmethod builtin.`, StaticMethodNew, nil)
type StaticMethod struct {
Callable Object
Dict StringDict
}
// Type of this StaticMethod object
func (o StaticMethod) Type() *Type {
return StaticMethodType
}
// Get the Dict
func (c *StaticMethod) GetDict() StringDict {
return c.Dict
}
// StaticMethodNew
func StaticMethodNew(metatype *Type, args Tuple, kwargs StringDict) (res Object, err error) {
c := &StaticMethod{}
err = UnpackTuple(args, kwargs, "staticmethod", 1, 1, &c.Callable)
if err != nil {
return nil, err
}
return c, nil
}
// Read a staticmethod from a class - no bound method here
func (c *StaticMethod) M__get__(instance, owner Object) (Object, error) {
return c.Callable, nil
}
// Properties
func init() {
StaticMethodType.Dict["__func__"] = &Property{
Fget: func(self Object) (Object, error) {
return self.(*StaticMethod).Callable, nil
},
}
}
// Check interface is satisfied
var _ IGetDict = (*StaticMethod)(nil)
var _ I__get__ = (*StaticMethod)(nil)
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

搜索帮助