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
abdf99d3
Commit
abdf99d3
authored
Mar 24, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow subclassing of properties
parent
b0ba8e15
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
src/runtime/descr.cpp
src/runtime/descr.cpp
+5
-4
test/tests/property.py
test/tests/property.py
+19
-0
No files found.
src/runtime/descr.cpp
View file @
abdf99d3
...
@@ -91,9 +91,7 @@ static Box* propertyDel(Box* self, Box* obj) {
...
@@ -91,9 +91,7 @@ static Box* propertyDel(Box* self, Box* obj) {
}
}
static
Box
*
property_copy
(
BoxedProperty
*
old
,
Box
*
get
,
Box
*
set
,
Box
*
del
)
{
static
Box
*
property_copy
(
BoxedProperty
*
old
,
Box
*
get
,
Box
*
set
,
Box
*
del
)
{
// In CPython, I think this can take a subclass of property, and will call the subclass's
RELEASE_ASSERT
(
isSubclass
(
old
->
cls
,
property_cls
),
""
);
// constructor... for now just enforce that it's a property object and inline the constructor:
RELEASE_ASSERT
(
old
->
cls
==
property_cls
,
""
);
if
(
!
get
)
if
(
!
get
)
get
=
old
->
prop_get
;
get
=
old
->
prop_get
;
...
@@ -102,7 +100,10 @@ static Box* property_copy(BoxedProperty* old, Box* get, Box* set, Box* del) {
...
@@ -102,7 +100,10 @@ static Box* property_copy(BoxedProperty* old, Box* get, Box* set, Box* del) {
if
(
!
del
)
if
(
!
del
)
del
=
old
->
prop_del
;
del
=
old
->
prop_del
;
// Optimization for the case when the old propery is not subclassed
if
(
old
->
cls
==
property_cls
)
return
new
BoxedProperty
(
get
,
set
,
del
,
old
->
prop_doc
);
return
new
BoxedProperty
(
get
,
set
,
del
,
old
->
prop_doc
);
return
runtimeCall
(
old
->
cls
,
ArgPassSpec
(
4
),
get
,
set
,
del
,
&
old
->
prop_doc
,
NULL
);
}
}
static
Box
*
propertyGetter
(
Box
*
self
,
Box
*
obj
)
{
static
Box
*
propertyGetter
(
Box
*
self
,
Box
*
obj
)
{
...
...
test/tests/property.py
View file @
abdf99d3
...
@@ -63,3 +63,22 @@ try:
...
@@ -63,3 +63,22 @@ try:
except
AttributeError
,
e
:
except
AttributeError
,
e
:
print
e
print
e
c
.
x
=
1
c
.
x
=
1
class
MyProperty
(
property
):
pass
class
C
(
object
):
v
=
"empty"
@
MyProperty
def
p
(
self
):
print
"get"
return
self
.
v
@
p
.
setter
def
p
(
self
,
value
):
print
"set"
self
.
v
=
"it "
+
value
c
=
C
()
c
.
p
=
"worked"
print
c
.
p
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