You may read the previous discussion this idea already was discussed.
If I understand correctly there are 2 possibilites
- Do not change syntax, and return value of
__with__
rebinds target value. This has a drawback of that loosy branch will rebind value toNone
and people mostly didn’t like the idea of rebinding the variable as being too magic. - Change the syntax to somehow has two variables. This has a drawback that syntax and semantic do change, which make a change less likely to be accepted and also this is the first time for Python to have
as
target not being set right after the statement
And in general the idea that “context manager has a return value” was not welcomed. Beasts like Timer
considered special enouth to have it’s own attribute based result handling. And I do think that, after all, rebinding is not a good idea.
I don’t see a use case for x = yield result
as there expected to be exactly one yield
, and zero or 2 or more is an error.
I would like to keep the scope of this proposal small to increase the chance of being accepted, things like “manager result variable” or “optinal execution of the body” can be added later as futher extention of __with__
.