py/objgenerator: Allow to hash generators and generator instances.
Adds nothing to the code size, since it uses existing empty slots in the type structures.
This commit is contained in:
parent
145796f037
commit
f69ab79ec8
@ -74,6 +74,7 @@ const mp_obj_type_t mp_type_gen_wrap = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_generator,
|
||||
.call = gen_wrap_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun) {
|
||||
@ -235,6 +236,7 @@ const mp_obj_type_t mp_type_gen_instance = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_generator,
|
||||
.print = gen_instance_print,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = gen_instance_iternext,
|
||||
.locals_dict = (mp_obj_dict_t*)&gen_instance_locals_dict,
|
||||
|
7
tests/basics/builtin_hash_gen.py
Normal file
7
tests/basics/builtin_hash_gen.py
Normal file
@ -0,0 +1,7 @@
|
||||
# test builtin hash function, on generators
|
||||
|
||||
def gen():
|
||||
yield
|
||||
|
||||
print(type(hash(gen)))
|
||||
print(type(hash(gen())))
|
@ -323,6 +323,7 @@ def run_tests(pyb, tests, args, base_path="."):
|
||||
skip_tests.update({'basics/%s.py' % t for t in 'with_break with_continue with_return'.split()}) # require complete with support
|
||||
skip_tests.add('basics/array_construct2.py') # requires generators
|
||||
skip_tests.add('basics/bool1.py') # seems to randomly fail
|
||||
skip_tests.add('basics/builtin_hash_gen.py') # requires yield
|
||||
skip_tests.add('basics/class_bind_self.py') # requires yield
|
||||
skip_tests.add('basics/del_deref.py') # requires checking for unbound local
|
||||
skip_tests.add('basics/del_local.py') # requires checking for unbound local
|
||||
|
Loading…
Reference in New Issue
Block a user