I would like to get a reference back to the function that created an iterator. In my case I am interested in getting the original docstring.
Example:
def my_generator():
"""this is my generator"""
for x in (1,2,3):
yield x
my_iter = my_generator()
# in another part of my code where I Only have access to the iterator
# no access to the generator function "my_generator"
assert my_iter.????.__doc__ == "this is my generator"
It feels hacky, but one way would to get at the docstring would be via
co_consts:I’d be more inclined to figure out some decorator to apply to a generator function to make sure the docstring stays.
If you need the function itself, how about:
but I make no promises that this works for every case..