[Python-Dev] PEP 550 v4
Ethan Furman
ethan at stoneleaf.us
Thu Sep 7 09:05:58 EDT 2017
More information about the Python-Dev mailing list
Thu Sep 7 09:05:58 EDT 2017
- Previous message (by thread): [Python-Dev] PEP 550 v4
- Next message (by thread): [Python-Dev] PEP 550 v4
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 > this: > > def fractions(precision, x, y): > ctx = decimal.getcontext().copy() > decimal.setcontext(ctx) > 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 clear. 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? -- ~Ethan~
- Previous message (by thread): [Python-Dev] PEP 550 v4
- Next message (by thread): [Python-Dev] PEP 550 v4
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list