I found this function quite useful for debugging. It is  __str__ and not __repr__ because I also don't like the internal change of state. However, the obvious way of printing a lexerstream print(lexerstream) will not work "as expected" because it will consume the whole input (ie, not restore the idx).
Maybe the problem is in the name of the function? Is there any other name that you would use for this function?