python-trio / trio

Trio – a friendly Python library for async concurrency and I/O
https://trio.readthedocs.io
Other
6.2k stars 341 forks source link

Add `TypeVarTuple` to `Nursery.start` #3023

Open jakkdl opened 4 months ago

jakkdl commented 4 months ago

2881 attempted to add TypeVarTuple to the signature of Nursery.start but hit problems and ended up blocked by https://github.com/python/mypy/issues/16522

I'm opening this issue so we can track it on our end as well, or possibly discuss alternate ways of adding type hints. We could consider having a million overloads like trio-typing did as a stop-gap.

Equivalent anyio issue: https://github.com/agronholm/anyio/issues/678

TeamSpen210 commented 4 months ago

A while back I tried writing code to generate those required overloads, just rebased it. It's very ugly, but I think it works with the exception of DTLSEndpoint.serve(). That's also using a variadic generic, I guess the layers of inference required became too much.

A5rocks commented 4 months ago

If we do go the overload route, remember that overload compatibility checks are quadratic. While I'm not sure it will affect users (I don't think mypy at least runs the compat checks cause the errors won't be reported anyways?), we should still make sure it doesn't balloon type checking time for developing trio.

jakkdl commented 4 months ago

Did the trio-typing plugin do something smarter than just generate a bunch of overloads? If so maybe we could strip it down to solely that functionality [and incorporate it here].

Although perhaps somebody should just try and contribute the feature upstream, although ilevkivskyi saying it would be tedious is a bit worrying.