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
98c6cc08
Commit
98c6cc08
authored
Oct 19, 2014
by
Travis Hance
Committed by
Travis Hance
Oct 29, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
property with set
parent
2775f89f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
src/runtime/descr.cpp
src/runtime/descr.cpp
+24
-0
test/tests/property.py
test/tests/property.py
+6
-1
No files found.
src/runtime/descr.cpp
View file @
98c6cc08
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
#include "codegen/compvars.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
namespace
pyston
{
...
...
@@ -31,6 +32,27 @@ static Box* propertyNew(Box* cls, Box* fget, Box* fset, Box** args) {
return
new
BoxedProperty
(
fget
,
fset
,
fdel
,
doc
);
}
static
Box
*
propertySet
(
Box
*
self
,
Box
*
obj
,
Box
*
val
)
{
BoxedProperty
*
prop
=
static_cast
<
BoxedProperty
*>
(
self
);
Box
*
func
;
if
(
val
==
NULL
)
{
func
=
prop
->
prop_del
;
}
else
{
func
=
prop
->
prop_set
;
}
if
(
func
==
NULL
)
{
raiseExcHelper
(
AttributeError
,
val
==
NULL
?
"can't delete attribute"
:
"can't set attribute"
);
}
if
(
val
==
NULL
)
{
runtimeCall
(
func
,
ArgPassSpec
(
1
),
obj
,
NULL
,
NULL
,
NULL
,
NULL
);
}
else
{
runtimeCall
(
func
,
ArgPassSpec
(
2
),
obj
,
val
,
NULL
,
NULL
,
NULL
);
}
return
None
;
}
void
setupDescr
()
{
member_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"member"
));
member_cls
->
giveAttr
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
memberGet
,
UNKNOWN
,
3
)));
...
...
@@ -39,6 +61,8 @@ void setupDescr() {
property_cls
->
giveAttr
(
"__name__"
,
boxStrConstant
(
"property"
));
property_cls
->
giveAttr
(
"__new__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
propertyNew
,
UNKNOWN
,
5
,
4
,
false
,
false
),
{
None
,
None
,
None
,
None
}));
property_cls
->
giveAttr
(
"__set__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
propertySet
,
UNKNOWN
,
3
,
0
,
false
,
false
)));
property_cls
->
freeze
();
}
...
...
test/tests/property.py
View file @
98c6cc08
...
...
@@ -2,7 +2,12 @@ class C(object):
def
fget
(
self
):
return
5
x
=
property
(
fget
)
def
fset
(
self
,
val
):
print
'in fset, val = '
,
val
x
=
property
(
fget
,
fset
)
c
=
C
()
print
c
.
x
c
.
x
=
7
print
c
.
x
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