No, it is not a generator function. Maybe you want it to be a generator function in the future but right now it is not a generator function.
The first technical issue is this question: how does the compiler know at compile time that o
is a context manager containing a yield
?
The compiler has to decide at compile time whether the def
statement builds a regular function or a generator function. It does that by looking for yield inside the function block. If there is no yield, and the value of o
is unknown until runtime, how does the compiler decide what to do?
But before we even get into the technical details, letâs talk about the most critical issues:
- What are you trying to do?
- Why are you trying to do it this way?
- What is this supposed to do, at runtime?
Iâve read this entire thread, and I still donât understand the motive behind it, or the use-case.
I think the motive is that you want to write asyncronous code without using asyncio, but Iâm not sure.
- Why do you want to avoid asyncio?
- Have you tried using an old-style generator-based coroutine?
The core devs arenât going to spend many hundreds of person-hours designing, discussing, implementing and testing a complex new feature if the answers are just âno particular reasonâ and âno I havenâtâ.
In your first post you showed us this usage:
g = generator()
while True:
next(g)
which is great, but I have no idea what that is supposed to do and how it will differ from the exact same code run today.
To explain your proposal, its not enough to just show a sample of how you use your feature, you also have to tell us what that code will do.
In another post, you have this:
with mutex: # wait for mutex
followed just ten lines later:
with mutex: # this will not wait for mutex
o_O
That looks like a contradiction to me. The exact same line of code will both wait for mutex and not wait for mutex. Is this something to do with quantum mechanics? How is the reader supposed to know which case it is, if the comment is missing or inaccurate? How does the interpreter decide between the two behaviours?