Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
779794a6
Commit
779794a6
authored
Aug 26, 2014
by
Damien George
Browse files
py: Add dispatch for user defined ==, >, <=, >=.
Addresses issue #827.
parent
fa1a9bc9
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/objtype.c
View file @
779794a6
...
...
@@ -381,11 +381,12 @@ STATIC const qstr binary_op_method_name[] = {
MP_BINARY_OP_INPLACE_MODULO,
MP_BINARY_OP_INPLACE_POWER,*/
[
MP_BINARY_OP_LESS
]
=
MP_QSTR___lt__
,
/*MP_BINARY_OP_MORE,
MP_BINARY_OP_EQUAL,
MP_BINARY_OP_LESS_EQUAL,
MP_BINARY_OP_MORE_EQUAL,
MP_BINARY_OP_NOT_EQUAL,
[
MP_BINARY_OP_MORE
]
=
MP_QSTR___gt__
,
[
MP_BINARY_OP_EQUAL
]
=
MP_QSTR___eq__
,
[
MP_BINARY_OP_LESS_EQUAL
]
=
MP_QSTR___le__
,
[
MP_BINARY_OP_MORE_EQUAL
]
=
MP_QSTR___ge__
,
/*
MP_BINARY_OP_NOT_EQUAL, // a != b calls a == b and inverts result
*/
[
MP_BINARY_OP_IN
]
=
MP_QSTR___contains__
,
/*
...
...
py/qstrdefs.h
View file @
779794a6
...
...
@@ -64,6 +64,10 @@ Q(__getattr__)
Q
(
__del__
)
Q
(
__call__
)
Q
(
__lt__
)
Q
(
__gt__
)
Q
(
__eq__
)
Q
(
__le__
)
Q
(
__ge__
)
Q
(
micropython
)
Q
(
bytecode
)
...
...
tests/basics/class_binop.py
0 → 100644
View file @
779794a6
class
foo
(
object
):
def
__init__
(
self
,
value
):
self
.
x
=
value
def
__eq__
(
self
,
other
):
print
(
'eq'
)
return
self
.
x
==
other
.
x
def
__lt__
(
self
,
other
):
print
(
'lt'
)
return
self
.
x
<
other
.
x
def
__gt__
(
self
,
other
):
print
(
'gt'
)
return
self
.
x
>
other
.
x
def
__le__
(
self
,
other
):
print
(
'le'
)
return
self
.
x
<=
other
.
x
def
__ge__
(
self
,
other
):
print
(
'ge'
)
return
self
.
x
>=
other
.
x
for
i
in
range
(
3
):
for
j
in
range
(
3
):
print
(
foo
(
i
)
==
foo
(
j
))
print
(
foo
(
i
)
<
foo
(
j
))
print
(
foo
(
i
)
>
foo
(
j
))
print
(
foo
(
i
)
<=
foo
(
j
))
print
(
foo
(
i
)
>=
foo
(
j
))
Write
Preview
Supports
Markdown
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