py: frozenset() creates an empty frozenset.
This commit is contained in:
parent
2323ef9182
commit
1d34e32431
17
py/objset.c
17
py/objset.c
@ -121,15 +121,19 @@ STATIC void set_print(void (*print)(void *env, const char *fmt, ...), void *env,
|
|||||||
|
|
||||||
|
|
||||||
STATIC mp_obj_t set_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
STATIC mp_obj_t set_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
|
||||||
// TODO check n_kw == 0
|
mp_arg_check_num(n_args, n_kw, 0, 1, false);
|
||||||
|
|
||||||
switch (n_args) {
|
switch (n_args) {
|
||||||
case 0:
|
case 0: {
|
||||||
// return a new, empty set
|
// create a new, empty set
|
||||||
return mp_obj_new_set(0, NULL);
|
mp_obj_set_t *set = mp_obj_new_set(0, NULL);
|
||||||
|
// set actual set/frozenset type
|
||||||
|
set->base.type = type_in;
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
default: { // can only be 0 or 1 arg
|
||||||
// 1 argument, an iterable from which we make a new set
|
// 1 argument, an iterable from which we make a new set
|
||||||
mp_obj_set_t *set = mp_obj_new_set(0, NULL);
|
mp_obj_set_t *set = mp_obj_new_set(0, NULL);
|
||||||
mp_obj_t iterable = mp_getiter(args[0]);
|
mp_obj_t iterable = mp_getiter(args[0]);
|
||||||
@ -141,9 +145,6 @@ STATIC mp_obj_t set_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
|
|||||||
set->base.type = type_in;
|
set->base.type = type_in;
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
|
||||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "set takes at most 1 argument, %d given", n_args));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ except NameError:
|
|||||||
import sys
|
import sys
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
s = frozenset()
|
||||||
|
print(s)
|
||||||
|
|
||||||
s = frozenset({1})
|
s = frozenset({1})
|
||||||
print(s)
|
print(s)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user