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
5a877503
Commit
5a877503
authored
Jan 16, 2014
by
Damien George
Browse files
Merge branch 'master' of github.com:dpgeorge/micropython
parents
8161a10d
10744dd8
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/runtime.c
View file @
5a877503
...
...
@@ -297,6 +297,24 @@ int rt_is_true(mp_obj_t arg) {
return
0
;
}
else
if
(
arg
==
mp_const_true
)
{
return
1
;
}
else
if
(
MP_OBJ_IS_QSTR
(
arg
))
{
// TODO: \0
return
*
qstr_str
(
MP_OBJ_QSTR_VALUE
(
arg
))
!=
0
;
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
str_type
))
{
// TODO: \0
return
*
qstr_str
(
mp_obj_str_get
(
arg
))
!=
0
;
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
list_type
))
{
uint
len
;
mp_obj_t
*
dummy
;
mp_obj_list_get
(
arg
,
&
len
,
&
dummy
);
return
len
!=
0
;
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
tuple_type
))
{
uint
len
;
mp_obj_t
*
dummy
;
mp_obj_tuple_get
(
arg
,
&
len
,
&
dummy
);
return
len
!=
0
;
}
else
if
(
MP_OBJ_IS_TYPE
(
arg
,
&
dict_type
))
{
return
mp_obj_dict_len
(
arg
)
!=
0
;
}
else
{
assert
(
0
);
return
0
;
...
...
tests/basics/tests/true-value.py
0 → 100644
View file @
5a877503
# Test true-ish value handling
if
not
False
:
print
(
"False"
)
if
not
0
:
print
(
"0"
)
if
not
""
:
print
(
"Empty string"
)
if
"foo"
:
print
(
"Non-empty string"
)
if
not
():
print
(
"Empty tuple"
)
if
(
""
,):
print
(
"Non-empty tuple"
)
if
not
[]:
print
(
"Empty list"
)
if
[
0
]:
print
(
"Non-empty list"
)
if
not
{}:
print
(
"Empty dict"
)
if
{
0
:
0
}:
print
(
"Non-empty dict"
)
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