A puzzle about the StopIteration exception

Here’s my solution, so far. I provide further evidence, which also puzzles me. Beyond that, I no longer claim to have removed my puzzlement. But perhaps I have reduced it. By the way, my underlying purpose it to well understand coroutines.

My evidence has the form of a test script, available on gitihub along with previous scripts. It’s purpose is to explore coroutine actions when an awaitable raises StopIteration(*args).

Here’s an extract, which provides a summary of results.

Coroutine actions when awaitable raises StopIteration(*args)

The test(*args) function returns a StopIteration exception, created
somewhat indirectly. We go via an async coroutine.

First an awaitable raises StopIteration(*args), in the context of a
coroutine that awaits an awaitable, and then returns its value.

We then catch and return the resulting StopIteration exception raised via the
coroutine. This is the value of test(*args).

The compare function effectively prints first the exception raised,
and then the exception received.

>>> def compare(*args):
...     print(repr(StopIteration(*args)))
...     print(repr(test(*args)))
...

>>> compare()
StopIteration()
StopIteration()

>>> compare(1)
StopIteration(1)
StopIteration(1)

>>> compare(1, 2)
StopIteration(1, 2)
StopIteration(1)

>>> compare(1, 2, 3)
StopIteration(1, 2, 3)
StopIteration(1)

>>> compare(None)
StopIteration(None)
StopIteration()