4 ms·
> Iterators, async functions and async iterators don't work well here because they have different semantics to standard functions. When you call them they retur
by xg15 5mo ago
> Iterators, async functions and async iterators don't work well here because they have different semantics to standard functions. When you call them they return immediately with a generator object, coroutine function and async generator object respectively. So the decorator completes immediately as opposed to the entire lifecycle what it's wrapping.
> This is an unfortunate problem I've encountered many times, and it's often a problem for normal decorators too. But this has changed in 3.15, now the ContextDecorator will check the type of the function it's wrapping and ensure that the decorator covers the entire lifespan.
I very much like the idea of that change - but it also seems kind of dangerous, to do this with no "opt-in mechanism", as that quite subtly changes the behavior of existing usage sites.
This is a bit of a "spacebar heating" situation, because someone would have to intentionally use a decorator in the old, broken way, but if someone actually did that, things may unexpectedly break.
- ameliaquining 5mo agoThe Python core team seems to think it's unlikely that anyone's relying on the existing behavior: https://github.com/python/cpython/pull/136212#issuecomment-4332309019 https://github.com/python/cpython/pull/136212#issuecomment-4...
- xg15 5mo agoOk, good to see that they checked that possibility. Looks like there was no situation in which the previous behavior could have been usable, so yeah, agreeing with the change then.
- Drakim 5mo agoEh, what's the worst that could happen? Developers opting to run an old version of Python due to incompatible changes? I can't see that happening.
- deleted 5mo ago[deleted]