FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gpython/py/classmethod.go at v0.0.2 · go-python/gpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
go-python
/
gpython
Public
Notifications
You must be signed in to change notification settings
Fork
105
Star
1k
Code
Issues
49
Pull requests
5
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
gpython
/
py
/
classmethod.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (59 loc) · 1.92 KB
Breadcrumbs
gpython
/
py
/
classmethod.go
Copy path
File metadata and controls
74 lines (59 loc) · 1.92 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2018 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// ClassMethod objects
package
py
var
ClassMethodType
=
ObjectType
.
NewType
(
"classmethod"
,
`classmethod(function) -> method
Convert a function to be a class method.
A class method receives the class as implicit first argument,
just like an instance method receives the instance.
To declare a class method, use this idiom:
class C:
def f(cls, arg1, arg2, ...): ...
f = classmethod(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.
If a class method is called for a derived class, the derived class
object is passed as the implied first argument.
Class methods are different than C++ or Java static methods.
If you want those, see the staticmethod builtin.`
,
ClassMethodNew
,
nil
)
type
ClassMethod
struct
{
Callable
Object
Dict
StringDict
}
// Type of this ClassMethod object
func
(
o
ClassMethod
)
Type
()
*
Type
{
return
ClassMethodType
}
// Get the Dict
func
(
c
*
ClassMethod
)
GetDict
()
StringDict
{
return
c
.
Dict
}
// ClassMethodNew
func
ClassMethodNew
(
metatype
*
Type
,
args
Tuple
,
kwargs
StringDict
) (
res
Object
,
err
error
) {
c
:=
&
ClassMethod
{}
err
=
UnpackTuple
(
args
,
kwargs
,
"classmethod"
,
1
,
1
,
&
c
.
Callable
)
if
err
!=
nil
{
return
nil
,
err
}
return
c
,
nil
}
// Read a classmethod from a class which makes a bound method
func
(
c
*
ClassMethod
)
M__get__
(
instance
,
owner
Object
) (
Object
,
error
) {
if
owner
==
nil
{
owner
=
instance
.
Type
()
}
return
NewBoundMethod
(
owner
,
c
.
Callable
),
nil
}
// Properties
func
init
() {
ClassMethodType
.
Dict
[
"__func__"
]
=
&
Property
{
Fget
:
func
(
self
Object
) (
Object
,
error
) {
return
self
.(
*
ClassMethod
).
Callable
,
nil
},
}
}
// Check interface is satisfied
var
_
IGetDict
=
(
*
ClassMethod
)(
nil
)
var
_
I__get__
=
(
*
ClassMethod
)(
nil
)
Back
|
FazBrowse Home
|
New Git URL