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
28a115d2
Commit
28a115d2
authored
Apr 17, 2015
by
Travis Hance
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get cpython/test_property.py to pass
parent
d5de0aad
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
29 deletions
+92
-29
from_cpython/Lib/test/test_property.py
from_cpython/Lib/test/test_property.py
+0
-1
src/runtime/descr.cpp
src/runtime/descr.cpp
+48
-28
test/tests/property.py
test/tests/property.py
+44
-0
No files found.
from_cpython/Lib/test/test_property.py
View file @
28a115d2
# expected: fail
# Test case for property
# more tests are in test_descr
...
...
src/runtime/descr.cpp
View file @
28a115d2
...
...
@@ -34,20 +34,9 @@ static Box* memberGet(BoxedMemberDescriptor* self, Box* inst, Box* owner) {
Py_FatalError
(
"unimplemented"
);
}
static
Box
*
propertyInit
(
Box
*
_self
,
Box
*
fget
,
Box
*
fset
,
Box
**
args
)
{
RELEASE_ASSERT
(
isSubclass
(
_self
->
cls
,
property_cls
),
""
);
Box
*
fdel
=
args
[
0
];
Box
*
doc
=
args
[
1
];
BoxedProperty
*
self
=
static_cast
<
BoxedProperty
*>
(
_self
);
self
->
prop_get
=
fget
;
self
->
prop_set
=
fset
;
self
->
prop_del
=
fdel
;
self
->
prop_doc
=
doc
;
self
->
getter_doc
=
false
;
/* if no docstring given and the getter has one, use that one */
if
((
doc
==
NULL
||
doc
==
None
)
&&
fget
!=
NULL
)
{
static
void
propertyDocCopy
(
BoxedProperty
*
prop
,
Box
*
fget
)
{
assert
(
prop
);
assert
(
fget
);
Box
*
get_doc
;
try
{
get_doc
=
getattrInternal
(
fget
,
"__doc__"
,
NULL
);
...
...
@@ -59,17 +48,34 @@ static Box* propertyInit(Box* _self, Box* fget, Box* fset, Box** args) {
}
if
(
get_doc
)
{
if
(
self
->
cls
==
property_cls
)
{
self
->
prop_doc
=
get_doc
;
if
(
prop
->
cls
==
property_cls
)
{
prop
->
prop_doc
=
get_doc
;
}
else
{
/* If this is a property subclass, put __doc__
in dict of the subclass instance instead,
otherwise it gets shadowed by __doc__ in the
class's dict. */
setattr
(
self
,
"__doc__"
,
get_doc
);
setattr
(
prop
,
"__doc__"
,
get_doc
);
}
self
->
getter_doc
=
true
;
prop
->
getter_doc
=
true
;
}
}
static
Box
*
propertyInit
(
Box
*
_self
,
Box
*
fget
,
Box
*
fset
,
Box
**
args
)
{
RELEASE_ASSERT
(
isSubclass
(
_self
->
cls
,
property_cls
),
""
);
Box
*
fdel
=
args
[
0
];
Box
*
doc
=
args
[
1
];
BoxedProperty
*
self
=
static_cast
<
BoxedProperty
*>
(
_self
);
self
->
prop_get
=
fget
;
self
->
prop_set
=
fset
;
self
->
prop_del
=
fdel
;
self
->
prop_doc
=
doc
;
self
->
getter_doc
=
false
;
/* if no docstring given and the getter has one, use that one */
if
((
doc
==
NULL
||
doc
==
None
)
&&
fget
!=
NULL
)
{
propertyDocCopy
(
self
,
fget
);
}
return
None
;
...
...
@@ -120,17 +126,31 @@ static Box* propertyDel(Box* self, Box* obj) {
static
Box
*
property_copy
(
BoxedProperty
*
old
,
Box
*
get
,
Box
*
set
,
Box
*
del
)
{
RELEASE_ASSERT
(
isSubclass
(
old
->
cls
,
property_cls
),
""
);
if
(
!
get
)
if
(
!
get
||
get
==
None
)
get
=
old
->
prop_get
;
if
(
!
set
)
if
(
!
set
||
set
==
None
)
set
=
old
->
prop_set
;
if
(
!
del
)
if
(
!
del
||
del
==
None
)
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
runtimeCall
(
old
->
cls
,
ArgPassSpec
(
4
),
get
,
set
,
del
,
&
old
->
prop_doc
,
NULL
);
if
(
old
->
cls
==
property_cls
)
{
BoxedProperty
*
prop
=
new
BoxedProperty
(
get
,
set
,
del
,
old
->
prop_doc
);
prop
->
getter_doc
=
false
;
if
((
old
->
getter_doc
&&
get
!=
None
)
||
!
old
->
prop_doc
)
propertyDocCopy
(
prop
,
get
);
return
prop
;
}
else
{
Box
*
doc
;
if
((
old
->
getter_doc
&&
get
!=
None
)
||
!
old
->
prop_doc
)
doc
=
None
;
else
doc
=
old
->
prop_doc
;
return
runtimeCall
(
old
->
cls
,
ArgPassSpec
(
4
),
get
,
set
,
del
,
&
doc
,
NULL
);
}
}
static
Box
*
propertyGetter
(
Box
*
self
,
Box
*
obj
)
{
...
...
test/tests/property.py
View file @
28a115d2
...
...
@@ -122,3 +122,47 @@ try:
f
=
property
(
ObjWithDocDesc
)
except
BaseException
as
e
:
print
e
.
message
print
'test the setting of a __doc__ when you copy it'
class
Desc
(
object
):
def
__get__
(
self
,
obj
,
typ
):
print
'desc called'
return
"blah"
class
ObjWithDocDesc
(
object
):
__doc__
=
Desc
()
prop
=
property
(
ObjWithDocDesc
)
print
'made prop'
print
prop
.
__doc__
def
g
():
"""doc of g"""
return
5
prop2
=
prop
.
getter
(
g
)
print
'made prop2'
print
prop2
.
__doc__
prop3
=
prop
.
setter
(
lambda
self
,
val
:
None
)
print
prop3
.
__doc__
prop4
=
prop
.
deleter
(
lambda
self
,
val
:
None
)
print
prop4
.
__doc__
print
'test the setting of a __doc__ when you copy it when using a subclass of property'
class
PropertySubclass
(
property
):
pass
class
Desc
(
object
):
def
__get__
(
self
,
obj
,
typ
):
print
'desc called'
return
"blah"
class
ObjWithDocDesc
(
object
):
__doc__
=
Desc
()
prop
=
PropertySubclass
(
ObjWithDocDesc
)
print
'made prop'
print
prop
.
__doc__
def
g
():
"""doc of g"""
return
5
prop2
=
prop
.
getter
(
g
)
print
'made prop2'
print
prop2
.
__doc__
prop3
=
prop
.
setter
(
lambda
self
,
val
:
None
)
print
prop3
.
__doc__
prop4
=
prop
.
deleter
(
lambda
self
,
val
:
None
)
print
prop4
.
__doc__
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