Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
8bc96471
Commit
8bc96471
authored
Jan 15, 2014
by
Paul Sokolovsky
Browse files
Implement "is" and "is not" operators.
So far, don't work for strings as expected.
parent
8eec8bca
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/runtime.c
View file @
8bc96471
...
...
@@ -461,6 +461,18 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
// then fail
// note that list does not implement + or +=, so that inplace_concat is reached first for +=
// deal with is, is not
if
(
op
==
RT_COMPARE_OP_IS
)
{
// TODO: may need to handle strings specially, CPython appears to
// assume all strings are interned (so "is" == "==" for strings)
return
MP_BOOL
(
lhs
==
rhs
);
}
if
(
op
==
RT_COMPARE_OP_IS_NOT
)
{
// TODO: may need to handle strings specially, CPython appears to
// assume all strings are interned (so "is" == "==" for strings)
return
MP_BOOL
(
lhs
!=
rhs
);
}
// deal with == and != for all types
if
(
op
==
RT_COMPARE_OP_EQUAL
||
op
==
RT_COMPARE_OP_NOT_EQUAL
)
{
if
(
mp_obj_equal
(
lhs
,
rhs
))
{
...
...
tests/basics/tests/is-isnot.py
0 → 100644
View file @
8bc96471
print
(
1
is
1
)
print
(
1
is
2
)
print
(
1
is
not
1
)
print
(
1
is
not
2
)
print
([
1
,
2
]
is
[
1
,
2
])
a
=
[
1
,
2
]
b
=
a
print
(
b
is
a
)
# TODO: strings require special "is" handling, postponed
# until qstr refactor.
#print("a" is "a")
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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