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
1ef88c12
Commit
1ef88c12
authored
Jul 05, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #652 from Daetalus/master
For issue #254, add lt, le, gt, ge to old-style class
parents
5ebb8cab
3974e784
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
0 deletions
+75
-0
src/runtime/classobj.cpp
src/runtime/classobj.cpp
+20
-0
test/tests/oldstyle_classes.py
test/tests/oldstyle_classes.py
+55
-0
No files found.
src/runtime/classobj.cpp
View file @
1ef88c12
...
...
@@ -741,6 +741,22 @@ Box* _instanceBinary(Box* _inst, Box* other, const char* attr) {
return
runtimeCall
(
func
,
ArgPassSpec
(
1
),
other
,
NULL
,
NULL
,
NULL
,
NULL
);
}
Box
*
instanceGt
(
Box
*
_inst
,
Box
*
other
)
{
return
_instanceBinary
(
_inst
,
other
,
"__gt__"
);
}
Box
*
instanceGe
(
Box
*
_inst
,
Box
*
other
)
{
return
_instanceBinary
(
_inst
,
other
,
"__ge__"
);
}
Box
*
instanceLt
(
Box
*
_inst
,
Box
*
other
)
{
return
_instanceBinary
(
_inst
,
other
,
"__lt__"
);
}
Box
*
instanceLe
(
Box
*
_inst
,
Box
*
other
)
{
return
_instanceBinary
(
_inst
,
other
,
"__le__"
);
}
Box
*
instanceEq
(
Box
*
_inst
,
Box
*
other
)
{
return
_instanceBinary
(
_inst
,
other
,
"__eq__"
);
}
...
...
@@ -856,6 +872,10 @@ void setupClassobj() {
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceCall
,
UNKNOWN
,
1
,
0
,
true
,
true
)));
instance_cls
->
giveAttr
(
"__eq__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceEq
,
UNKNOWN
,
2
)));
instance_cls
->
giveAttr
(
"__ne__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceNe
,
UNKNOWN
,
2
)));
instance_cls
->
giveAttr
(
"__lt__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceLt
,
UNKNOWN
,
2
)));
instance_cls
->
giveAttr
(
"__le__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceLe
,
UNKNOWN
,
2
)));
instance_cls
->
giveAttr
(
"__gt__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceGt
,
UNKNOWN
,
2
)));
instance_cls
->
giveAttr
(
"__ge__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
instanceGe
,
UNKNOWN
,
2
)));
instance_cls
->
freeze
();
instance_cls
->
tp_getattro
=
instance_getattro
;
...
...
test/tests/oldstyle_classes.py
View file @
1ef88c12
...
...
@@ -128,6 +128,61 @@ print issubclass(OldStyleClass, object)
print
isinstance
(
OldStyleClass
(),
OldStyleClass
)
print
issubclass
(
OldStyleClass
,
OldStyleClass
)
class
LessEqualTest
:
def
__init__
(
self
,
a
):
self
.
_a
=
a
def
__lt__
(
self
,
other
):
print
"lt"
return
self
.
_a
<
other
.
_a
def
__le__
(
self
,
other
):
print
"le"
return
self
.
_a
<=
other
.
_a
ca
=
LessEqualTest
(
3
)
cb
=
LessEqualTest
(
2
)
cc
=
LessEqualTest
(
2
)
print
(
ca
<
cb
)
print
(
cb
<
ca
)
print
(
ca
<=
cb
)
print
(
ca
<=
cc
)
# CompareA only defines __lt__ and __le__ but appears on the right-hand-side
print
(
ca
>
cb
)
print
(
ca
>=
cb
)
print
(
cb
>
ca
)
print
(
cb
>
cc
)
class
GreatEqualTest
:
def
__init__
(
self
,
a
):
self
.
_a
=
a
def
__gt__
(
self
,
other
):
print
"gt"
return
self
.
_a
>
other
.
_a
def
__ge__
(
self
,
other
):
print
"ge"
return
self
.
_a
>=
other
.
_a
cd
=
GreatEqualTest
(
4
)
ce
=
GreatEqualTest
(
5
)
cf
=
GreatEqualTest
(
4
)
print
(
cd
>=
ce
)
print
(
cd
>
ce
)
print
(
cd
>=
cf
)
print
(
cd
>
cf
)
# CompareB only defines __gt__ and __ge__ but appears on the right-hand-side
print
(
cd
<=
ce
)
print
(
cd
<
ce
)
print
(
cd
<=
cf
)
print
(
cd
<
cf
)
class
GetattrTest
:
def
__getattr__
(
self
,
attr
):
print
"getattr"
,
attr
...
...
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