[Python-Dev] PEP 550 v4

Elvis Pranskevichus elprans at gmail.com
Thu Sep 7 10:13:46 EDT 2017

On Thursday, September 7, 2017 6:37:58 AM EDT Greg Ewing wrote:
> 2) You ignore it and always use a context manager, in
> which case it's not strictly necessary for the implicit
> context push to occur, since the relevant context managers
> can take care of it.
> So there doesn't seem to be any great advantage to the
> automatic context push, and it has some disadvantages,
> such as yield-from not quite working as expected in
> some situations.

The advantage is that context managers don't need to *always* 
allocate and push an LC. [1]

> Also, it seems that every generator is going to incur
> the overhead of allocating a logical_context even when
> it doesn't actually change any context vars, which most
> generators won't.

By default, generators reference an empty LogicalContext object that is 
allocated once (like the None object).  We can do that because LCs are 


[1] https://mail.python.org/pipermail/python-dev/2017-September/

More information about the Python-Dev mailing list