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
c6ee2734
Commit
c6ee2734
authored
Dec 07, 2015
by
pohmelie
Committed by
Paul Sokolovsky
Dec 07, 2015
Browse files
py: Add min/max "default" keyword argument
parent
354e688d
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/modbuiltins.c
View file @
c6ee2734
...
...
@@ -254,6 +254,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter);
STATIC
mp_obj_t
mp_builtin_min_max
(
mp_uint_t
n_args
,
const
mp_obj_t
*
args
,
mp_map_t
*
kwargs
,
mp_uint_t
op
)
{
mp_map_elem_t
*
key_elem
=
mp_map_lookup
(
kwargs
,
MP_OBJ_NEW_QSTR
(
MP_QSTR_key
),
MP_MAP_LOOKUP
);
mp_map_elem_t
*
default_elem
;
mp_obj_t
key_fn
=
key_elem
==
NULL
?
MP_OBJ_NULL
:
key_elem
->
value
;
if
(
n_args
==
1
)
{
// given an iterable
...
...
@@ -269,7 +270,12 @@ STATIC mp_obj_t mp_builtin_min_max(mp_uint_t n_args, const mp_obj_t *args, mp_ma
}
}
if
(
best_obj
==
MP_OBJ_NULL
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_ValueError
,
"arg is an empty sequence"
));
default_elem
=
mp_map_lookup
(
kwargs
,
MP_OBJ_NEW_QSTR
(
MP_QSTR_default
),
MP_MAP_LOOKUP
);
if
(
default_elem
!=
NULL
)
{
best_obj
=
default_elem
->
value
;
}
else
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_ValueError
,
"arg is an empty sequence"
));
}
}
return
best_obj
;
}
else
{
...
...
py/qstrdefs.h
View file @
c6ee2734
...
...
@@ -235,6 +235,7 @@ Q(map)
#if MICROPY_PY_BUILTINS_MIN_MAX
Q
(
max
)
Q
(
min
)
Q
(
default
)
#endif
Q
(
namedtuple
)
Q
(
next
)
...
...
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