[Python-Dev] PEP 550 v4
ethan at stoneleaf.us
Thu Sep 7 09:05:58 EDT 2017
On 09/07/2017 03:37 AM, Greg Ewing wrote:
> If I understand correctly, instead of using a context
> manager, your fractions example could be written like
> def fractions(precision, x, y):
> ctx = decimal.getcontext().copy()
> ctx.prec = precision
> yield MyDecimal(x) / MyDecimal(y)
> yield MyDecimal(x) / MyDecimal(y ** 2)
> and it would work without leaking changes to the decimal
> context, despite the fact that it doesn't use a context
> manager or do anything else to explicitly put back the
> old context.
The disagreement seems to be whether a LogicalContext should be created implicitly vs explicitly (or opt-out vs opt-in).
As a user trying to track down a decimal context change not propagating, I would not suspect the above code of
automatically creating a LogicalContext and isolating the change, whereas Greg's context manager version is abundantly
The implicit vs explicit argument comes down, I think, to resource management: some resources in Python are
automatically managed (memory), and some are not (files) -- which type should LCs be?
More information about the Python-Dev