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
0ab9061c
Commit
0ab9061c
authored
Oct 29, 2014
by
Travis Hance
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added __get__ for property
parent
98c6cc08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
1 deletion
+22
-1
src/runtime/descr.cpp
src/runtime/descr.cpp
+19
-0
test/tests/property.py
test/tests/property.py
+3
-1
No files found.
src/runtime/descr.cpp
View file @
0ab9061c
...
...
@@ -32,7 +32,24 @@ static Box* propertyNew(Box* cls, Box* fget, Box* fset, Box** args) {
return
new
BoxedProperty
(
fget
,
fset
,
fdel
,
doc
);
}
static
Box
*
propertyGet
(
Box
*
self
,
Box
*
obj
,
Box
*
type
)
{
RELEASE_ASSERT
(
self
->
cls
==
property_cls
,
""
);
BoxedProperty
*
prop
=
static_cast
<
BoxedProperty
*>
(
self
);
if
(
obj
==
NULL
||
obj
==
None
)
{
return
self
;
}
if
(
prop
->
prop_get
==
NULL
)
{
raiseExcHelper
(
AttributeError
,
"unreadable attribute"
);
}
return
runtimeCall
(
prop
->
prop_get
,
ArgPassSpec
(
1
),
obj
,
NULL
,
NULL
,
NULL
,
NULL
);
}
static
Box
*
propertySet
(
Box
*
self
,
Box
*
obj
,
Box
*
val
)
{
RELEASE_ASSERT
(
self
->
cls
==
property_cls
,
""
);
BoxedProperty
*
prop
=
static_cast
<
BoxedProperty
*>
(
self
);
Box
*
func
;
if
(
val
==
NULL
)
{
...
...
@@ -61,6 +78,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
(
"__get__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
propertyGet
,
UNKNOWN
,
3
,
0
,
false
,
false
)));
property_cls
->
giveAttr
(
"__set__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
propertySet
,
UNKNOWN
,
3
,
0
,
false
,
false
)));
property_cls
->
freeze
();
...
...
test/tests/property.py
View file @
0ab9061c
...
...
@@ -3,11 +3,13 @@ class C(object):
return
5
def
fset
(
self
,
val
):
print
'in fset, val =
'
,
val
print
'in fset, val ='
,
val
x
=
property
(
fget
,
fset
)
c
=
C
()
print
c
.
x
print
C
.
x
.
__get__
(
c
,
C
)
print
type
(
C
.
x
.
__get__
(
None
,
C
))
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