Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
78ab3861
Commit
78ab3861
authored
Jan 12, 2016
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1034 from undingen/classmethod_sub
Allow subclassing classmethod and staticmethod
parents
4ae4660a
9d0fc1f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
4 deletions
+22
-4
src/runtime/descr.cpp
src/runtime/descr.cpp
+4
-4
test/tests/static_class_methods.py
test/tests/static_class_methods.py
+18
-0
No files found.
src/runtime/descr.cpp
View file @
78ab3861
...
...
@@ -186,7 +186,7 @@ static Box* propertyDeleter(Box* self, Box* obj) {
}
static
Box
*
staticmethodInit
(
Box
*
_self
,
Box
*
f
)
{
RELEASE_ASSERT
(
_self
->
cls
==
staticmethod_cls
,
""
);
RELEASE_ASSERT
(
isSubclass
(
_self
->
cls
,
staticmethod_cls
)
,
""
);
BoxedStaticmethod
*
self
=
static_cast
<
BoxedStaticmethod
*>
(
_self
);
self
->
sm_callable
=
f
;
...
...
@@ -194,7 +194,7 @@ static Box* staticmethodInit(Box* _self, Box* f) {
}
static
Box
*
staticmethodGet
(
Box
*
self
,
Box
*
obj
,
Box
*
type
)
{
RELEASE_ASSERT
(
self
->
cls
==
staticmethod_cls
,
""
);
RELEASE_ASSERT
(
isSubclass
(
self
->
cls
,
staticmethod_cls
)
,
""
);
BoxedStaticmethod
*
sm
=
static_cast
<
BoxedStaticmethod
*>
(
self
);
...
...
@@ -210,7 +210,7 @@ extern "C" PyObject* PyClassMethod_New(PyObject* callable) noexcept {
}
static
Box
*
classmethodInit
(
Box
*
_self
,
Box
*
f
)
{
RELEASE_ASSERT
(
_self
->
cls
==
classmethod_cls
,
""
);
RELEASE_ASSERT
(
isSubclass
(
_self
->
cls
,
classmethod_cls
)
,
""
);
BoxedClassmethod
*
self
=
static_cast
<
BoxedClassmethod
*>
(
_self
);
self
->
cm_callable
=
f
;
...
...
@@ -218,7 +218,7 @@ static Box* classmethodInit(Box* _self, Box* f) {
}
static
Box
*
classmethodGet
(
Box
*
self
,
Box
*
obj
,
Box
*
type
)
{
RELEASE_ASSERT
(
self
->
cls
==
classmethod_cls
,
""
);
RELEASE_ASSERT
(
isSubclass
(
self
->
cls
,
classmethod_cls
)
,
""
);
BoxedClassmethod
*
cm
=
static_cast
<
BoxedClassmethod
*>
(
self
);
...
...
test/tests/static_class_methods.py
View file @
78ab3861
...
...
@@ -24,3 +24,21 @@ def g(cls, a, b, c, d):
f
.
__get__
(
c
,
C
)(
17
,
18
,
19
,
20
)
g
.
__get__
(
c
,
C
)(
21
,
22
,
23
,
24
)
class
classonlymethod
(
classmethod
):
def
__get__
(
self
,
instance
,
owner
):
if
instance
is
not
None
:
raise
AttributeError
(
"This method is available only on the class, not on instances."
)
return
super
(
classonlymethod
,
self
).
__get__
(
instance
,
owner
)
class
C
(
object
):
@
classonlymethod
def
f
(
cls
):
print
"f called"
C
.
f
()
try
:
C
().
f
()
except
AttributeError
,
e
:
print
e
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment