I am trying (as an exercise) to type Curio's source code, but I have stumbled on a problem with its variable length tuples in the yielding parts of the code.
Curio's traps yield to the kernel a tuple of a known length, but the traps yield different lengths of tuples than each other.
For example, the curio.traps._read_wait(fileobj)
yields a 4-tuple of type Tuple[int, int, int, str]
whereas curio.traps._spawn(coro)
yields a 2 tuple of type Tuple[int, Coroutine]
.
The similarity between all their yield types is that the first item is always an int
but the rest have type Any
.
In the kernel, when it runs the coroutine to the next yield point, it expects an int
as the first item and Any
s after that. I was expecting Tuple[int, Any, ...]
to maaybe work, but it gives an error saying that the ...
was unexpected.
from typing import Tuple, Any
# Test code
vltuple: Tuple[int, Any, ...] = (1, 2)
vltuple = (1, 2, 3)
vltuple = (1, 'a', 'b')
vltuple = (1, [], 4.5)
Here are the exact error messages:
____.py:4: error: Unexpected '...'
____.py:4: error: Incompatible types in assignment (expression has type "Tuple[int]", variable has type "Tuple[int, Any, Any]")