Fix StopIteration error on Python >= 3.7
The current behavior errors on Python 3.7+ due to a backwards incompatible change: https://peps.python.org/pep-0479/
The current behavior errors on Python 3.7+ due to a backwards incompatible change: https://peps.python.org/pep-0479/