Replace uses of types.coroutine with a class#3266
Conversation
|
This is a valid workaround. I think it is less clear and probably slower, though. I would prefer not to make the change unless there is an actual improvement from it or upstream removes the capability we’re currently relying on. I still think the latter would be a mistake, but it’s outside of our control. |
|
I did try a few micro-benchmarks (running a few million |
|
Could you get some concrete numbers? I think |
| class _AsyncYield: | ||
| """Helper for the bottommost 'yield'. | ||
|
|
||
| You can't use 'yield' inside an async function, so implement an awaitable object to do so. |
There was a problem hiding this comment.
You can use yield inside an async function! It just doesn't do what we want.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3266 +/- ##
=============================================
Coverage 99.93728% 99.93728%
=============================================
Files 126 126
Lines 19132 19133 +1
Branches 1296 1296
=============================================
+ Hits 19120 19121 +1
Misses 10 10
Partials 2 2
🚀 New features to boost your workflow:
|
|
Let's close this until there's actually some consensus; we'll have time before any change lands and then arrives in a version we support. |
After seeing a discuss.python.org thread about finally deprecating
types.coroutine, I thought I'd try pre-emptively removing the two internal places in Trio which uses it. Both are to yield one value, to terminate theawaitstack. Also removed atyping.cast(), though we could have actually fixed that without the class change.Instead of a class, we could also just copy over the code that sets the relevant bitflag in the code object, but this is much more robust and future proof. I imagine that flag will also be removed at some point.
@oremanj since you just posted in that thread.