[Python-Dev] PEP 550 v4

Yury Selivanov yselivanov.ml at gmail.com
Wed Sep 6 20:08:31 EDT 2017

On Wed, Sep 6, 2017 at 5:00 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nathaniel Smith wrote:
>> Literally the first motivating example at the beginning of the PEP
>> ('def fractions ...') involves only generators, not coroutines, and
>> only works correctly if generators get special handling. (In fact, I'd
>> be curious to see how Greg's {push,pop}_local_storage could handle
>> this case.)
> I've given a decimal-based example, but it was a bit
> scattered. Here's a summary and application to the
> fractions example.
> I'm going to assume that the decimal module has been
> modified to keep the current context in a context var,
> and that getcontext() and setcontext() access that
> context var.
> THe decimal.localcontext context manager is also
> redefined as:
>    class localcontext():
>       def __enter__(self):
>          push_local_context()
>          ctx = getcontext().copy()
>          setcontext(ctx)
>          return ctx
>       def __exit__(self):
>          pop_local_context()

1. So essentially this means that we will have one "local context" per
context manager storing one value.

2. If somebody makes a mistake and calls "push_local_context" without
a corresponding "pop_local_context" -- you will have an unbounded
growth of LCs (happen's in Koos' proposal too, btw).

3. Users will need to know way more to correctly use the mechanism.

So far, both you and Koos can't give us a realistic example which
illustrates why we should suffer the implications of (1), (2), and


More information about the Python-Dev mailing list