Typeerror: 'nonetype' Object Is Not Iterable When Applying Decorator To Generator
I have a decorator function which I want to apply to both normal function and a generator. When applied to the normal function, it works properly. However, when applied to the gene
Solution 1:
When you add @decorator
, f_generator()
in for item in f_generator():
is actually decor(f_generator)
. Since decor()
does not yield or return anything, it's not iterable itself, you should add yield item
around for item in func(*args, **kwargs):
Solution 2:
the problem is with your last loop. you are iterating over the function wrapper
since that is what you get when calling f_generator()
and wrapper is not an iterator.
you can simply replace the last for loop with a call to your function. this is a nice tutorial i learned a lot from about decorators
Post a Comment for "Typeerror: 'nonetype' Object Is Not Iterable When Applying Decorator To Generator"